Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vivekrk1992/5e8c70daee6cd39bcc086bb3abfe2910 to your computer and use it in GitHub Desktop.
Save vivekrk1992/5e8c70daee6cd39bcc086bb3abfe2910 to your computer and use it in GitHub Desktop.
Python graphql request
```
pip install --pre gql[all]
or if use zsh
pip install --pre gql\[all\]
```
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
# Select your transport with a defined url endpoint
transport = AIOHTTPTransport(url="http://localhost:8001/graphql/")
# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)
query = gql(
"""query {
allGender {
id
name
}
}
"""
)
result = client.execute(query)
print(result)
@vivekrk1992
Copy link
Author

with access key
reqHeaders = {
'x-api-key' : API_KEY,
'Authorization': 'Bearer ' + TOKEN_KEY // This is the key
}

_transport = RequestsHTTPTransport(
url=API_ENDPOINT,
headers = reqHeaders,
use_json=True,
)

client = Client(
transport = _transport,
fetch_schema_from_transport=True,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment