Dedicated helper for posting GraphQL queries. Sets the `application/json` content type and json.dumps the variables if present.
(
self,
query,
variables=None,
permissions=None,
check_no_permissions=True,
**kwargs,
)
| 72 | return super().post(API_PATH, data, **kwargs) |
| 73 | |
| 74 | def post_graphql( |
| 75 | self, |
| 76 | query, |
| 77 | variables=None, |
| 78 | permissions=None, |
| 79 | check_no_permissions=True, |
| 80 | **kwargs, |
| 81 | ): |
| 82 | """Dedicated helper for posting GraphQL queries. |
| 83 | Sets the `application/json` content type and json.dumps the variables |
| 84 | if present. |
| 85 | """ |
| 86 | data = {"query": query} |
| 87 | if variables is not None: |
| 88 | data["variables"] = variables |
| 89 | if data: |
| 90 | data = json.dumps(data, cls=DjangoJSONEncoder) |
| 91 | kwargs["content_type"] = "application/json" |
| 92 | |
| 93 | if permissions: |
| 94 | if check_no_permissions: |
| 95 | response = super().post(API_PATH, data, **kwargs) |
| 96 | assert_no_permission(response) |
| 97 | self.user.user_permissions.add(*permissions) |
| 98 | return super().post(API_PATH, data, **kwargs) |
| 99 | |
| 100 | def post_multipart(self, *args, permissions=None, **kwargs): |
| 101 | """Send a multipart POST request. |
no test coverage detected