githubEdit

GraphQL

GraphQL is Shopify's preferred API language – it's the way developers are encouraged to query for and submit Shopify data. Mechanic tasks frequently use GraphQL to efficiently retrieve and write data from Shopify.

circle-exclamation

Reading data with GraphQL

Use the shopify Liquid filter to run a GraphQL query inline during a task run. The result is available immediately.

{% capture query %}
  query {
    orders(first: 5, query: "financial_status:paid") {
      nodes {
        id
        name
        totalPriceSet {
          shopMoney {
            amount
          }
        }
      }
    }
  }
{% endcapture %}

{% assign result = query | shopify %}

{% for order in result.data.orders.nodes %}
  {{ order.name }}: {{ order.totalPriceSet.shopMoney.amount }}
{% endfor %}

Learn more: Queries

Writing data with GraphQL

Use the Shopify action to run GraphQL mutations. Mutations are queued during the task run and performed after the script finishes.

Learn more: Mutations

Learn more

Last updated

Was this helpful?