graphql
Executes queries and mutations against Shopify's GraphQL Admin API. The response is stored in a variable for further processing.
{% graphql query: product_query, variables: my_variables as result %}
{% if result.product %}
{% log result.product.title %}
{% endif %}Syntax
{% graphql query: query_string, variables: variables_object as result_variable %}Parameters
query
Yes
GraphQL query or mutation string
variables
No
Object containing variables for the GraphQL operation
Result Object
The result contains the returned data directly accessible at the top level. Query fields are available as properties on the result variable.
Example query:
{% graphql query: product_query, variables: vars as result %}
{% comment %} Access result.product directly, not result.data.product {% endcomment %}If errors occur, they are available in the errors property:
errors
array/null
Array of error objects if the operation failed
Example result for a product query:
Examples
Basic product query:
Update product with mutation:
Paginated query with cursor:
Query with dynamic variables:
Handle errors gracefully:
Notes
Consumes 1 credit per operation
Uses the store's API version configured in DataJet
GraphQL errors are automatically logged to the script logs
Throttling is handled for you: throttled (
THROTTLED/ HTTP 429) and transient server errors are retried automatically with backoff. Do not add your ownTHROTTLEDchecks or retry loopsVariables must be a valid object (use
jsontag to construct complex variables)For large datasets, use pagination with cursors to avoid timeouts
Result properties are accessed directly (e.g.,
result.products, notresult.data.products)Refer to Shopify's GraphQL Admin API documentation for available queries and mutations
Last updated