(self, request, *args, **kwargs)
| 151 | |
| 152 | @method_decorator(ensure_csrf_cookie) |
| 153 | def dispatch(self, request, *args, **kwargs): |
| 154 | try: |
| 155 | if request.method.lower() not in ("get", "post"): |
| 156 | raise HttpError( |
| 157 | HttpResponseNotAllowed( |
| 158 | ["GET", "POST"], "GraphQL only supports GET and POST requests." |
| 159 | ) |
| 160 | ) |
| 161 | |
| 162 | data = self.parse_body(request) |
| 163 | show_graphiql = self.graphiql and self.can_display_graphiql(request, data) |
| 164 | |
| 165 | if show_graphiql: |
| 166 | return self.render_graphiql( |
| 167 | request, |
| 168 | # Dependency parameters. |
| 169 | whatwg_fetch_version=self.whatwg_fetch_version, |
| 170 | whatwg_fetch_sri=self.whatwg_fetch_sri, |
| 171 | react_version=self.react_version, |
| 172 | react_sri=self.react_sri, |
| 173 | react_dom_sri=self.react_dom_sri, |
| 174 | graphiql_version=self.graphiql_version, |
| 175 | graphiql_sri=self.graphiql_sri, |
| 176 | graphiql_css_sri=self.graphiql_css_sri, |
| 177 | subscriptions_transport_ws_version=self.subscriptions_transport_ws_version, |
| 178 | subscriptions_transport_ws_sri=self.subscriptions_transport_ws_sri, |
| 179 | graphiql_plugin_explorer_version=self.graphiql_plugin_explorer_version, |
| 180 | graphiql_plugin_explorer_sri=self.graphiql_plugin_explorer_sri, |
| 181 | graphiql_plugin_explorer_css_sri=self.graphiql_plugin_explorer_css_sri, |
| 182 | # The SUBSCRIPTION_PATH setting. |
| 183 | subscription_path=self.subscription_path, |
| 184 | # GraphiQL headers tab, |
| 185 | graphiql_header_editor_enabled=graphene_settings.GRAPHIQL_HEADER_EDITOR_ENABLED, |
| 186 | graphiql_should_persist_headers=graphene_settings.GRAPHIQL_SHOULD_PERSIST_HEADERS, |
| 187 | graphiql_input_value_deprecation=graphene_settings.GRAPHIQL_INPUT_VALUE_DEPRECATION, |
| 188 | ) |
| 189 | |
| 190 | if self.batch: |
| 191 | responses = [self.get_response(request, entry) for entry in data] |
| 192 | result = "[{}]".format( |
| 193 | ",".join([response[0] for response in responses]) |
| 194 | ) |
| 195 | status_code = ( |
| 196 | responses |
| 197 | and max(responses, key=lambda response: response[1])[1] |
| 198 | or 200 |
| 199 | ) |
| 200 | else: |
| 201 | result, status_code = self.get_response(request, data, show_graphiql) |
| 202 | |
| 203 | return HttpResponse( |
| 204 | status=status_code, content=result, content_type="application/json" |
| 205 | ) |
| 206 | |
| 207 | except HttpError as e: |
| 208 | response = e.response |
| 209 | response["Content-Type"] = "application/json" |
| 210 | response.content = self.json_encode( |
nothing calls this directly
no test coverage detected