Skip to content

Add headers arg to GraphQLTestCase.query #827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions graphene_django/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUpClass(cls):

cls._client = Client()

def query(self, query, op_name=None, input_data=None, variables=None):
def query(self, query, op_name=None, input_data=None, variables=None, headers=None):
"""
Args:
query (string) - GraphQL query to run
Expand All @@ -36,7 +36,9 @@ def query(self, query, op_name=None, input_data=None, variables=None):
are provided, the ``input`` field in the ``variables``
dict will be overwritten with this value.
variables (dict) - If provided, the "variables" field in GraphQL will be
set to this value.
set to this value.
headers (dict) - If provided, the headers in POST request to GRAPHQL_URL
will be set to this value.

Returns:
Response object from client
Expand All @@ -51,10 +53,17 @@ def query(self, query, op_name=None, input_data=None, variables=None):
body["variables"]["input"] = input_data
else:
body["variables"] = {"input": input_data}

resp = self._client.post(
self.GRAPHQL_URL, json.dumps(body), content_type="application/json"
)
if headers:
resp = self._client.post(
self.GRAPHQL_URL,
json.dumps(body),
content_type="application/json",
**headers
)
else:
resp = self._client.post(
self.GRAPHQL_URL, json.dumps(body), content_type="application/json"
)
return resp

def assertResponseNoErrors(self, resp):
Expand Down