Shopify GraphQL: Practical Guide with Code Examples

Master Shopify GraphQL with practical code examples: queries, mutations, pagination, and rate limits. Admin API and Storefront API explained step by step.

Profile picture of Lasse Lung, CEO & Co-Founder at Qualimero
Lasse Lung
CEO & Co-Founder at Qualimero
April 13, 202610 min read

What is Shopify GraphQL?

I spoke with a Shopify merchant last week who had three different apps making dozens of REST calls just to render a product page. Each response carried 90% data the app never used. One migration to GraphQL later, those dozens of calls became three.

GraphQL is a query language for APIs, originally released by Facebook as open source in 2015. The core idea: you define exactly which data fields you need, and the API returns precisely that. Nothing more, nothing less. With a traditional REST API, you hit a fixed endpoint and receive a predefined data structure, often loaded with fields your application never touches.

Shopify introduced GraphQL in 2018. As of October 2024, the REST Admin API is officially legacy. Since April 2025, all new public apps in the Shopify App Store must use the Shopify GraphQL Admin API documentation exclusively. This is not an optional recommendation, it is the direction Shopify is taking.

For developers and store owners working with the Shopify API, GraphQL is no longer a nice-to-have. It is the standard. And after the initial learning curve, it is genuinely more efficient than REST.

GraphQL vs REST on Shopify

The decision between GraphQL and REST on Shopify is no longer a decision. It has been made. Still, the direct comparison helps to understand why Shopify chose this path and where the practical differences matter.

Shopify GraphQL vs REST: direct comparison
CriterionGraphQLREST (Legacy)
Data fetchingReturns exactly the requested fieldsFixed response structure with overfetching
EndpointsSingle endpoint for all operationsDozens of individual endpoints
Nested dataRelated data in a single requestMultiple requests required
VersioningQuarterly (2026-01, 2026-04)Quarterly, but legacy status
Rate limitsCost-based: 100 points/second (Standard)Request-based: 2 requests/second
Bulk operationsNative support for large datasetsNot available
Learning curveSteeper entry, faster productivityEasier start, higher complexity at scale
FutureActive developmentLegacy since October 2024

The most important difference in practice: overfetching. When you query a customer's orders via REST, you receive the complete order structure every time. With GraphQL, you specify in your query that you only need the order number, date, and total amount. That saves bandwidth, reduces load times, and makes your application more efficient.

Setting up the Shopify GraphQL Admin API

I had a conversation with a store owner recently who assumed GraphQL was only for large development teams. He had his first query running within 20 minutes. The barrier to entry is lower than most people expect.

For the Shopify GraphQL Admin API, you need three things: a Shopify store with custom app access, an Admin API access token, and an HTTP client. Shopify also offers the GraphiQL Explorer directly in the admin panel, ideal for testing queries before moving them into production code.

Set up Shopify GraphQL in 4 steps
1
Create a custom app

In the Shopify Admin under Settings > Apps and Sales Channels > Develop Apps, create a new custom app.

2
Define API scopes

Select the required Admin API scopes: read_products, write_products, read_orders, depending on your use case.

3
Generate access token

After installing the app, copy the Admin API access token. This token is displayed only once.

4
Run your first query

Send the token as an X-Shopify-Access-Token header to the GraphQL endpoint and execute your first query.

The GraphQL endpoint for the Admin API follows this pattern:

endpoint.sh
bash
POST https://{your-store}.myshopify.com/admin/api/2026-01/graphql.json

Here is a simple first query using curl that retrieves your shop information:

first-query.sh
bash
curl -X POST \
  https://your-store.myshopify.com/admin/api/2026-01/graphql.json \
  -H 'Content-Type: application/json' \
  -H 'X-Shopify-Access-Token: your-access-token' \
  -d '{
    "query": "{ shop { name email myshopifyDomain } }"
  }'
Illustration of the Shopify GraphQL authentication process with access token and secure API endpoint
Authentication with the Admin API uses the X-Shopify-Access-Token header.

Essential queries and mutations

GraphQL distinguishes between queries (reading data) and mutations (changing data). In practice, you will use both daily. These are the operations I set up first in nearly every Shopify project.

Querying products

products-query.graphql
graphql
query {
  products(first: 10) {
    edges {
      node {
        id
        title
        status
        variants(first: 5) {
          edges {
            node {
              price
              inventoryQuantity
              sku
            }
          }
        }
      }
    }
  }
}

This query fetches the first 10 products with up to 5 variants each. You get ID, title, status, price, inventory, and SKU in a single call. With REST, you would first query the products, then load the variants for each product separately.

Querying orders

orders-query.graphql
graphql
query {
  orders(first: 5, sortKey: CREATED_AT, reverse: true) {
    edges {
      node {
        id
        name
        createdAt
        totalPriceSet {
          shopMoney {
            amount
            currencyCode
          }
        }
        customer {
          firstName
          lastName
          email
        }
      }
    }
  }
}

Orders, customer data, and prices in a single request. The sortKey and reverse parameters sort by creation date descending. This is the kind of efficiency you do not want to give up once you have experienced it.

Creating a product (mutation)

product-create.graphql
graphql
mutation {
  productCreate(input: {
    title: "Premium Garden Tool Set"
    productType: "Garden Supplies"
    vendor: "GardenPro"
    status: DRAFT
  }) {
    product {
      id
      title
      status
    }
    userErrors {
      field
      message
    }
  }
}

Mutations always return a userErrors array. This is not optional, it is your primary error channel. If userErrors is empty, the operation succeeded. If not, the message field tells you exactly what went wrong.

Common Shopify GraphQL queries and mutations
OperationTypeUse case
productsQueryFetch product data, variants, and inventory levels
ordersQueryLoad orders with customer and pricing data
customersQueryQuery customer data and order history
productCreateMutationCreate a new product with variants
productUpdateMutationUpdate existing product data
orderMarkAsPaidMutationMark an order as paid
inventoryAdjustQuantitiesMutationUpdate inventory levels

Pagination and large datasets

Shopify GraphQL uses cursor-based pagination. Instead of page 1, 2, 3, you receive a cursor pointing to the next record. This is more reliable than offset-based pagination, especially with large and frequently changing datasets.

pagination-query.graphql
graphql
query {
  products(first: 50, after: "eyJsYXN0X2lkIjoxMjM0NTY3ODkwfQ==") {
    edges {
      node {
        id
        title
      }
      cursor
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

pageInfo.hasNextPage tells you whether more data exists. pageInfo.endCursor is the value you pass as the after parameter in your next request. That is how you iterate through the entire dataset, reliably and without skipping records.

Rate limits and performance

Shopify does not calculate rate limits by request count. Instead, every query has a calculated cost value based on the number of objects and connections it requests. The system is called Calculated Query Cost, and understanding it is the difference between a smooth integration and a throttled one.

Shopify GraphQL rate limits by plan
100 pts/s
Standard plan

100 cost points per second, bucket of 1,000 points

200 pts/s
Advanced plan

Double capacity for growing stores

1,000 pts/s
Shopify Plus

Enterprise capacity for high-volume operations. Source: Shopify rate limits documentation

Query costs are calculated before execution (requestedQueryCost). After execution, the actual consumption is determined (actualQueryCost), and the difference is refunded. You can optimize the cost of any query in advance by requesting only the fields you actually need.

cost-response.json
json
{
  "extensions": {
    "cost": {
      "requestedQueryCost": 42,
      "actualQueryCost": 28,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 972,
        "restoreRate": 100
      }
    }
  }
}

Send the header Shopify-GraphQL-Cost-Debug: 1 with your requests to get a detailed cost breakdown per field. This is the fastest way to identify expensive queries and optimize them before they hit production.

Storefront API with GraphQL

Beyond the Admin API, Shopify offers a second GraphQL interface: the Storefront API. It is designed for customer-facing applications, meaning custom storefronts, mobile apps, and headless commerce projects with Shopify Hydrogen.

Admin API vs Storefront API
FeatureAdmin APIStorefront API
PurposeBackend management (products, orders, customers)Frontend experiences (custom storefronts, apps)
AuthenticationAccess token required (server-side)Storefront access token (can be used in frontend)
Data accessFull access to store dataPublic data only (products, collections, checkout)
Rate limitsCost-based (100-1,000 pts/s)No request rate limits, complexity limit only
IDsStandard Global IDsBase64-encoded IDs

For headless commerce, the recommended stack is Storefront API combined with Hydrogen and Shopify Oxygen. The Storefront API intentionally has no request rate limits, designed to handle traffic spikes like flash sales without throttling.

GraphQL in practice: automation with AI

Open the dashboard of a mid-sized e-commerce store and you see immediately why manual API calls do not scale. Hundreds of products, daily inventory changes, seasonal pricing adjustments. This is where GraphQL combined with AI employees becomes genuinely powerful.

An AI employee can query product data through the GraphQL Admin API to advise customers in real time. It knows inventory levels, prices, variants, and availability without anyone manually maintaining that data. Signed, an online retailer for custom and decorative signs, deployed Qualimero's digital employee Alex to handle customer inquiries on Instagram and TikTok. The result: 18x ROI, 70% customer support automation, and a 30% increase in upselling. Read the full Signed case study.

The connection works in reverse too. Shopify Webhooks URL PENDING] can serve as triggers for automated GraphQL mutations. New order received? The AI employee checks inventory via GraphQL and updates availability. Customer question via WhatsApp? It fetches order data with a query and responds in seconds. Combined with [AI product consultation, this creates a fully automated advisory layer running on live shop data.

Better APIs are only half the equation

An AI employee uses the Shopify GraphQL API to advise your customers in real time, based on live product data, inventory levels, and order history. Our clients see cart value increases of up to 35%.

Book a demo

Common errors and troubleshooting

After hundreds of GraphQL integrations, I know the five errors nearly every developer hits at the start. Here they are, each with its fix.

  1. Authentication error (401): The X-Shopify-Access-Token header is missing or invalid. Verify that the token was copied correctly and the app is installed.
  2. Missing scopes (403): The app lacks the required API permissions. Add the missing scopes in the Shopify Admin under app settings and regenerate the token.
  3. Query syntax errors: GraphQL is strictly typed. A missing comma or incorrect nesting causes an immediate parsing error. Use the GraphiQL Explorer to test queries before moving them into code.
  4. Rate limit exceeded (THROTTLED): Query costs exceed the available budget. Reduce the number of objects per query or switch to Bulk Operations for large datasets.
  5. Type errors in mutations: Incorrect input types, such as a string where an ID is expected or a missing required parameter. Check the userErrors in the response for the affected field and error message.
Illustration of a debug console showing GraphQL error analysis and solutions
Most GraphQL errors can be quickly narrowed down using the userErrors response and the cost debug header.

FAQ

Yes. GraphQL is Shopify's primary API technology for reading and modifying store data. Since April 2025, all new public Shopify apps must use the GraphQL Admin API exclusively. The REST Admin API has been classified as legacy since October 2024.

For new projects, yes. GraphQL eliminates overfetching, allows nested queries in a single request, and offers native Bulk Operations support for large datasets. Shopify is investing exclusively in GraphQL and no longer actively developing the REST API.

You send an HTTP POST request to your store's GraphQL endpoint with an access token in the header. The request body contains a GraphQL query or mutation as JSON. The endpoint follows this pattern: https://your-store.myshopify.com/admin/api/2026-01/graphql.json.

Shopify uses cursor-based pagination. Each query returns a pageInfo object with hasNextPage and endCursor. Pass the endCursor value as the after parameter in your next request to load the next page of results.

Rate limits are based on calculated query costs, not requests per second. Standard stores receive 100 cost points per second with a bucket of 1,000 points. Advanced stores get 200 points, and Shopify Plus stores receive 1,000 points per second.

GraphQL allows more efficient data retrieval, reduces API call volume, and gives Shopify better visibility into which fields apps actually use. This enables faster API evolution and more targeted deprecation of unused features. Existing REST integrations continue to work, but all new development should use GraphQL.

Automate your Shopify store with AI

An AI employee accesses your product data through the GraphQL API and advises customers in real time. No coding required, no flow builder, with genuine product understanding.

Book a free demo
About the Author
Lasse Lung
Lasse Lung
CEO & Co-Founder · Qualimero

Lasse is CEO and co-founder of Qualimero. After completing his MBA at WHU and scaling a company to seven-figure revenue, he founded Qualimero to build AI-powered digital employees for e-commerce. His focus: helping businesses measurably improve customer interaction through intelligent automation.

KI-StrategieE-CommerceDigitale Transformation

Related Articles

Hire your first digital employee now!