Shopify GraphQL recipes
Queries and mutations for the jobs developers search for most: bulk exports, metafields, products, inventory, discounts, orders and the Storefront cart.
In short
These are copy-ready GraphQL documents for Shopify’s Admin and Storefront APIs, version 2026-10. Each page has the query or mutation, example variables, the access scopes it needs and what the response looks like. Every document and its variables are validated against Shopify’s published schema before we publish. The REST Admin API is legacy, so new apps should use these GraphQL calls.
- 27 pages, free to use in any store, including client work (MIT license)
Bulk operations
Export and import large amounts of data without paging through it.
Export all products with a bulk operation
Export every Shopify product and variant to a JSONL file with bulkOperationRunQuery, then poll the operation and download the result.
Export orders for a date range with a bulk operation
Export every Shopify order in a date range, with line items, to a JSONL file using bulkOperationRunQuery and an orders search filter.
Import data with a staged upload and bulkOperationRunMutation
Run one mutation thousands of times: upload a JSONL file of variables with stagedUploadsCreate, then start bulkOperationRunMutation.
Metafields and metaobjects
Store and read your own data on products, customers and more.
Write metafields with metafieldsSet
Create or update up to 25 metafields on any resource in one atomic call with metafieldsSet, with compareDigest to avoid overwriting newer values.
Create a metafield definition
Create a typed, validated metafield definition with metafieldDefinitionCreate, pin it in the admin and expose it to the Storefront API.
Create a metaobject definition and upsert entries
Model a size chart as a metaobject: create the definition with metaobjectDefinitionCreate, then create or update entries by handle with metaobjectUpsert.
Products and inventory
Create products and variants, and keep stock in sync.
Create or update a whole product with productSet
Sync a product from an external system in one call: productSet creates or updates the product, its options and variants, matched by handle.
Create and update many variants at once
Add new sizes or colors with productVariantsBulkCreate and change prices on many variants with productVariantsBulkUpdate, one product per call.
Set stock levels from an external system
Overwrite available stock per item and location with inventorySetQuantities, using changeFromQuantity and an idempotency key as 2026-10 requires.
Read stock levels by location
Read available, on hand, committed and incoming stock for every item at a location, or for one item across all locations.
Group products into a combined listing
Show separate color products as one listing: create a parent product, then attach the children and their option values with combinedListingUpdate.
Discounts and Functions
Create discounts and switch Functions on from code.
Turn on a discount Function as an automatic discount
Activate your discount Function in a store with discountAutomaticAppCreate: function handle, discount classes, combinations and a JSON config metafield.
Add discount codes in bulk
Add up to 250 unique codes per call to an existing code discount with discountRedeemCodeBulkAdd, then check which codes were imported.
Activate a delivery, payment or validation Function
Turn on a deployed Function in a store with deliveryCustomizationCreate, paymentCustomizationCreate or validationCreate, with its settings as a metafield.
Orders and customers
Edit orders, create drafts, fulfill, refund and tag.
Edit an order after it was placed
Add items, change quantities and commit the change with orderEditBegin, orderEditAddVariant, orderEditSetQuantity and orderEditCommit.
Create a draft order with custom prices
Create a quote or B2B order with draftOrderCreate: override a variant’s price with priceOverride and add custom line items with their own price.
Fulfill an order with a tracking number
Read the open fulfillment orders of an order, then create a fulfillment with carrier, tracking number and URL using fulfillmentCreate.
Refund an order
Calculate a refund with suggestedRefund, then refund line items, restock them and return the money with refundCreate and an idempotency key.
Add tags to orders, customers or products in bulk
Tag one resource with tagsAdd without overwriting its tags, or thousands at once by running tagsAdd in a bulk mutation operation.
List the customers in a segment
Page through the members of a customer segment with customerSegmentMembers, or run an ad hoc segment query with customerSegmentMembersQueryCreate.
Translate content, also per market
Read a resource’s translatable content and digests with translatableResource, then save translations, optionally for one market, with translationsRegister.
Webhooks
Get told when something changes instead of polling.
Subscribe to a webhook with a filter
Only receive the webhooks you need: create a subscription with webhookSubscriptionCreate and a filter in Shopify search syntax, or in shopify.app.toml.
Storefront API
Carts, local prices and custom data for headless storefronts.
Create a cart and add items with the Storefront API
Build a headless cart: cartCreate with lines and buyer country, cartLinesAdd for more items, and checkoutUrl to send the buyer to checkout.
Show local prices and languages with @inContext
Get prices in the buyer’s currency and content in their language from the Storefront API by adding @inContext(country, language) to the query.
Read metafields and metaobjects with the Storefront API
Read a product’s metafields, follow a metaobject reference such as a size chart, and list all metaobjects of a type like FAQs.
Basics
Pagination, query cost and rate limits.
Read query cost and throttle status
Every Admin API response reports its cost and the remaining bucket in extensions.cost. Use it to pace requests and handle THROTTLED errors.
Page through results with cursors
Read every product, order or customer page by page: ask for pageInfo, pass endCursor as after, and stop when hasNextPage is false.
About the code
- Validated against the Admin or Storefront API schema for version 2026-10 on the date shown. Check the version in your request URL.
- IDs and store addresses in the examples are placeholders. Replace them with your own.
- Admin API calls need an access token from your app. Never put an Admin API token in a storefront or theme.
- MIT license. Use the code in your own store or in client work.
Need this built, tested and maintained for your store? See API integrations.
Questions
- Is the Shopify REST Admin API deprecated?
- Shopify calls it legacy since October 2024, and new public apps have had to use GraphQL since April 2025. Shopify has not announced a date to switch REST off entirely. Each recipe here names the REST call it replaces.
- Where can I run these queries?
- In the GraphiQL app for your store, in your app’s code with an access token, or with the Shopify CLI. Storefront API queries also run from a browser with a public Storefront token.
- Which API version do the recipes use?
- Version 2026-10, the latest stable version on the date each page was checked. Most documents also work on the versions before and after it; the page notes any field that changed.
