I can’t see how to format this graphene query for shopify. I need to replicate this curl query with graphene in Django:
curl -X POST
"https://<shop>.myshopify.com/api/graphql"
-H "Content-Type: application/graphql"
-H "X-Shopify-Storefront-Access-Token: <storefront-access-token>"
-d '
{
shop {
collections(first: 5) {
edges {
node {
id
handle
}
}
pageInfo {
hasNextPage
}
}
}
}
'
So far I have:
access_token = 'some_token'
headers = (
{ "Content-Type": "application/graphql" },
{ "X-Shopify-Storefront-Access-Token": access_token},
)
schema = graphene.Schema(query=Query)
print(schema)
result = schema.execute('{
catsinuniform {
collections(first: 5) {
edges {
node {
id
handle
}
}
pageInfo {
hasNextPage
}
}
}'')
print(result.data['catsinuniform'])
This syntax is wrong for graphene but I don’t get how it should look? Once I have the data in the right format I can then do a requests post to get the informaiton I want from the shopify storefrontapi
2
Answers
Graphene is an implemention of the GraphQL spec for Python, meant for creating and executing your own GraphQL schema. It is not a GraphQL client for making requests to existing GraphQL servers. You can make calls to the Shopify API using any regular HTTP library, like
requests
, or you can use something like gql. A simple example:As of version 5.1.0 of the Shopify Python API, support for querying the Shopify Admin API with Graphql is included:
Shopify Python API Graphql Docs