> For the complete documentation index, see [llms.txt](https://learn.mechanic.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.mechanic.dev/platform/graphql.md).

# GraphQL

Use Shopify's GraphQL Admin API in Mechanic Shopify automation tasks to read and write store data — orders, products, customers, metafields, and more.

Mechanic tasks have direct inline access to Shopify's GraphQL Admin API. Run queries during task execution to read data, and use GraphQL mutations via the Shopify action to write data — giving you the same level of API access you'd have in a custom app, without the infrastructure.

{% hint style="warning" %}
Shopify REST is deprecated in Mechanic. All new tasks should use the GraphQL Admin API. See [Converting tasks from Shopify REST to GraphQL](/resources/converting-tasks-from-shopify-rest-to-graphql.md) for migration guidance.
{% endhint %}

## Reading data with GraphQL

Use the [`shopify` Liquid filter](/platform/liquid/filters.md#shopify) to run a GraphQL query inline during a task run. The result is available immediately.

```liquid
{% 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](/platform/graphql/basics/queries.md)

## Writing data with GraphQL

Use the [Shopify action](/core/actions/shopify.md) to run GraphQL mutations. Mutations are queued during the task run and **performed after the task code finishes**.

```liquid
{% action "shopify" %}
  mutation {
    tagsAdd(id: "gid://shopify/Order/1234567890", tags: ["reviewed"]) {
      node {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
{% endaction %}
```

Learn more: [Mutations](/platform/graphql/basics/mutations.md)

## Learn more

* [GraphQL in Liquid](/core/shopify/read/graphql-in-liquid.md) — the complete guide to using GraphQL queries in task code
* [Shopify Admin API GraphiQL explorer](/platform/graphql/basics/shopify-admin-api-graphiql-explorer.md) — test queries interactively
* [Queries](/platform/graphql/basics/queries.md) — reading data with GraphQL
* [Mutations](/platform/graphql/basics/mutations.md) — writing data with GraphQL
* [Pagination](/platform/graphql/basics/pagination.md) — handling paginated results
* [Bulk operations](/platform/graphql/bulk-operations.md) — processing large datasets
* [Converting tasks from Shopify REST to GraphQL](/resources/converting-tasks-from-shopify-rest-to-graphql.md) — migration guide for existing tasks


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learn.mechanic.dev/platform/graphql.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
