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

Parameter
Required
Description

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:

Property
Type
Description

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:

Bulk operation query:

Notes

  • Consumes 1 credit per operation

  • Uses the store's API version configured in DataJet

  • GraphQL errors are automatically logged to the script logs

  • Variables must be a valid object (use json tag to construct complex variables)

  • For large datasets, use pagination with cursors to avoid timeouts

  • Result properties are accessed directly (e.g., result.products, not result.data.products)

  • Refer to Shopify's GraphQL Admin API documentationarrow-up-right for available queries and mutations

Last updated