Skip to main content

snippets_py

Integration

New integration from credential
graphql_client = yepcode.integration.graphql('credential-slug')
New integration from plain authentication data
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

transport = AIOHTTPTransport(url='https://api.spacex.land/graphql/', headers={})
graphql_client = Client(transport=transport, fetch_schema_from_transport=True)

Query

from gql import gql

query = gql(
"""
query launchesPast($limit: 10) {
launchesPast(limit: $limit) {
mission_name
}
}
"""
)

try:
data = graphql_client.execute(query, variable_values={ 'limit': 10 })
print(data)
except Exception as err:
print(err)
raise

Query with Headers


from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

transport = AIOHTTPTransport(
url='https://api.spacex.land/graphql/',
headers={ 'CustomHeader': 'value' }
)

graphql_client = Client(transport=transport, fetch_schema_from_transport=True)

query = gql(
"""
query launchesPast($limit: 10) {
launchesPast(limit: $limit) {
mission_name
}
}
"""
)

try:
data = graphql_client.execute(query, variable_values={ 'limit': 10 })
print(data)
except Exception as err:
print(err)
raise

Mutation

from gql import gql

query = gql(
"""
mutation insert_users($objects: [user_inser_input!]!) {
insert_users(objects: $objects) {
returning {
name
}
}
}
"""
)

variable_values = {
'objects': [
{
'name': 'JohnLocke',
'rocket': 'JohnLocke',
'timestamp': '1990-12-31T23:59:59.999Z',
'twitter': 'JohnLocke'
}
]
}

try:
data = graphql_client.execute(query, variable_values=variable_values)
print(data)
except Exception as err:
print(err)
raise