name: shopify-graphql-reference description: Reference Vercel Shop GraphQL patterns, fragments, cache conventions, and transforms for any Shopify GraphQL work in the template.
Shopify GraphQL Reference
Description
Use this skill as the reference source for Shopify GraphQL work in the template. It keeps queries, mutations, schema validation, fragment changes, locale handling, caching rules, and transforms aligned with the live Shopify schema and established storefront patterns.
When to Use This Skill
- When the user is doing any Shopify GraphQL work
- When the user wants a new query or mutation
- When an existing operation needs more fields
- When a GraphQL response shape must be mapped into domain types
- When debugging Shopify GraphQL errors, missing fields, or stale cache behavior
- When invoked via
/vercel-shop:shopify-graphql-reference
Read These First
- Read references/REFERENCE.md for the detailed technical reference: operation structure, fragment usage, locale context, cache rules, and common modifications.
- Use
shopify-ai-toolkitor thevercel-shop:fetch-shopify-schemaskill when you need authoritative schema facts for the Storefront or Customer Account APIs.
Workflow
1. Verify the schema first
- Verify fields, types, enum values, and arguments with
shopify-ai-toolkitbefore writing or changing GraphQL. - Never guess Shopify field names, enum values, or argument shapes.
- Do not add repo-local schema snapshots or
.claudefolders to the template.
2. Choose the right operation file
- Add the operation to the closest existing file in
lib/shopify/operations/when the concern already exists there. - Create a new operation file only when the concern is genuinely new.
- Always call
shopifyFetchwith a stableoperationname, a GraphQL document string, andvariablespassed as an object.
3. Reuse fragments deliberately
- Use
PRODUCT_FRAGMENTfor PDP-level product data. - Use
PRODUCT_CARD_FRAGMENTfor listings, search results, and other lighter product cards. - Extend
lib/shopify/fragments.tswhen several operations need the same fields.
4. Handle locale context correctly
- Locale-sensitive reads should use
@inContext(...). - Use helpers from
lib/i18nto derive country and language codes instead of hardcoding them. - Keep locale flowing through the operation API so pages and components stay consistent.
5. Apply cache rules to reads
- Read operations should include
"use cache: remote",cacheLife(...), andcacheTag(...). - Pick existing cache tags when the data belongs to an established surface.
- Mutations should not use read-cache directives.
- Every cart mutation must call
invalidateCartCache()after the write succeeds.
6. Transform before returning
- Convert Shopify response shapes to domain types before they cross into components.
- Keep raw Shopify types inside
lib/shopify/**. - Update the matching transform and domain type when you add new fields.
7. Verify the change
- Re-check the query against the live schema with
shopify-ai-toolkit. - Check that the operation name passed to
shopifyFetchmatches the GraphQL operation name. - Run the smallest relevant validation command for the touched area.
Guardrails
- Always verify Shopify GraphQL fields against the live schema via
shopify-ai-toolkit. - Never interpolate dynamic values directly into the query string when GraphQL variables can carry them.
- Use
PRODUCT_CARD_FRAGMENTfor listings andPRODUCT_FRAGMENTfor PDP work unless there is a clear reason not to. - Return domain types from operations, not raw Shopify response types.
- Cart mutations must call
invalidateCartCache().
Common changes
Add a field to an existing product query
- Confirm the field exists in the live Storefront API schema with
shopify-ai-toolkit. - Add it to the appropriate fragment in
lib/shopify/fragments.ts. - Update the Shopify response type and transform in
lib/shopify/transforms/product.ts. - Add the mapped field to
lib/types.tsif components need it.
Add a new read operation
- Define the GraphQL query using existing fragments where possible.
- Add
"use cache: remote",cacheLife(...), andcacheTag(...). - Call
shopifyFetchwith the query and variables object. - Transform the response before returning it.
Add a mutation
- Define the mutation and typed response shape.
- Call
shopifyFetchwithout read-cache directives. - If the mutation touches cart state, call
invalidateCartCache(). - Return transformed domain data.
Debug GraphQL errors
- Set
DEBUG_SHOPIFY=truein.env.localto log Shopify requests with timing and variables. - Compare every field and argument against the live schema with
shopify-ai-toolkit. - Check whether the wrong fragment is being reused for the surface.
See also
- the
vercel-shop:fetch-shopify-schemaskill references/REFERENCE.mdvercel-shop:enable-shopify-authvercel-shop:enable-shopify-cms