Created
April 5, 2021 07:26
-
-
Save vivekrk1992/5e8c70daee6cd39bcc086bb3abfe2910 to your computer and use it in GitHub Desktop.
Python graphql request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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,
)