(self, request)
| 259 | return json.dumps(d, sort_keys=True, indent=2, separators=(",", ": ")) |
| 260 | |
| 261 | def parse_body(self, request): |
| 262 | content_type = self.get_content_type(request) |
| 263 | |
| 264 | if content_type == "application/graphql": |
| 265 | return {"query": request.body.decode()} |
| 266 | |
| 267 | elif content_type == "application/json": |
| 268 | # noinspection PyBroadException |
| 269 | try: |
| 270 | body = request.body.decode("utf-8") |
| 271 | except Exception as e: |
| 272 | raise HttpError(HttpResponseBadRequest(str(e))) |
| 273 | |
| 274 | try: |
| 275 | request_json = json.loads(body) |
| 276 | if self.batch: |
| 277 | assert isinstance(request_json, list), ( |
| 278 | "Batch requests should receive a list, but received {}." |
| 279 | ).format(repr(request_json)) |
| 280 | assert ( |
| 281 | len(request_json) > 0 |
| 282 | ), "Received an empty list in the batch request." |
| 283 | else: |
| 284 | assert isinstance( |
| 285 | request_json, dict |
| 286 | ), "The received data is not a valid JSON query." |
| 287 | return request_json |
| 288 | except AssertionError as e: |
| 289 | raise HttpError(HttpResponseBadRequest(str(e))) |
| 290 | except (TypeError, ValueError): |
| 291 | raise HttpError(HttpResponseBadRequest("POST body sent invalid JSON.")) |
| 292 | |
| 293 | elif content_type in [ |
| 294 | "application/x-www-form-urlencoded", |
| 295 | "multipart/form-data", |
| 296 | ]: |
| 297 | return request.POST |
| 298 | |
| 299 | return {} |
| 300 | |
| 301 | def execute_graphql_request( |
| 302 | self, request, data, query, variables, operation_name, show_graphiql=False |
no test coverage detected