-
Notifications
You must be signed in to change notification settings - Fork 186
Closed
Labels
type: documentationAn issue or pull request for improving or updating the documentationAn issue or pull request for improving or updating the documentationtype: question or discussionIssue discussing or asking a question about gqlIssue discussing or asking a question about gql
Description
I'm trying to set cookies in the transport to execute a query.
This works when I use RequestsHTTPTransport
but not when I use AIOHTTPTransport
.
The cookie needs to be present in the POST request. In case it's not present, the client gets redirected to the login page.
So if I'm using requests
library directly, it should look like this:
cookies = authenticate(url, username, password)
json = { 'query' : '{ queryName { id }}' }
r = requests.post(url, json=json, cookies=cookies)
This works:
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from gql.transport.requests import RequestsHTTPTransport
cookies=authenticate(url, username, password).get_dict()
transport = RequestsHTTPTransport(url=url, timeout=900, cookies=cookies)
with Client(
transport=transport,
# fetch_schema_from_transport=True,
execute_timeout=1200,
) as client:
query = gql('''
query {
queryName { id }
}
''')
result = client.execute(query)
print(result)
This redirects me to the login page.
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
cookies=authenticate(url, username, password).get_dict()
transport = AIOHTTPTransport(url=url, timeout=900, cookies=cookies)
async with Client(
transport=transport,
# fetch_schema_from_transport=True,
execute_timeout=1200,
) as client:
query = gql('''
query {
queryName { id }
}
''')
result = await client.execute(query)
print(result)
I need to send the same cookies for uploading a file via graphQL which is why I need to use AIOHttpTransport
. How do I send cookies the same way as in requests?
Note: Tried sending via extra_args
but that didn't work.
Metadata
Metadata
Assignees
Labels
type: documentationAn issue or pull request for improving or updating the documentationAn issue or pull request for improving or updating the documentationtype: question or discussionIssue discussing or asking a question about gqlIssue discussing or asking a question about gql