# GraphQL

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](https://learn.mechanic.dev/resources/converting-tasks-from-shopify-rest-to-graphql) for migration guidance.
{% endhint %}

## Reading data with GraphQL

Use the [`shopify` Liquid filter](https://learn.mechanic.dev/liquid/filters#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](https://learn.mechanic.dev/platform/graphql/basics/queries)

## Writing data with GraphQL

Use the [Shopify action](https://learn.mechanic.dev/core/actions/shopify) 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](https://learn.mechanic.dev/platform/graphql/basics/mutations)

## Learn more

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