Shopify GraphQL Codegen: Why Types Fall Back to any

Shopify GraphQL codegen is one dev dependency and one command. Install @shopify/api-codegen-preset, point a .graphqlrc.ts at your Admin API version, mark each query string with #graphql, and run graphql-codegen. After that, admin.graphql() types its variables and its response from a generated admin.generated.d.ts, with no generics to write by hand.

The React Router app template already ships the config and the script. It does not ship the output, so a new app has untyped responses until somebody runs the command once. The behaviour described below was run on 26 November 2026 with @shopify/api-codegen-preset 3.0.1, @graphql-codegen/cli 6.3.1, @shopify/shopify-app-react-router 4.0.4, TypeScript 5.8.2 and the Admin API 2026-10 schema.

How do you set up Shopify GraphQL codegen?

Shopify’s guide to typing GraphQL operations installs the preset and the two API clients, then adds a script:

npm add --save-dev @shopify/api-codegen-preset
npm add @shopify/admin-api-client @shopify/storefront-api-client
npm pkg set scripts.graphql-codegen=graphql-codegen

The second line looks redundant, because the app package already depends on both clients. Under pnpm it is the line that makes the types apply at all, because the generated file refers to @shopify/admin-api-client by name.

The config goes in .graphqlrc.ts at the project root:

import {ApiType, shopifyApiProject} from '@shopify/api-codegen-preset';

export default {
  schema: 'https://shopify.dev/admin-graphql-direct-proxy/2026-10',
  documents: ['./app/**/*.{ts,tsx}'],
  projects: {
    default: shopifyApiProject({
      apiType: ApiType.Admin,
      apiVersion: '2026-10',
      documents: ['./app/**/*.{ts,tsx}'],
      outputDir: './app/types',
    }),
  },
};

Set apiVersion yourself. The preset’s README lists the default as “Oldest stable version”, and the example in Shopify’s guide still pins 2023-10.

npm run graphql-codegen then writes three files into app/types. admin-2026-10.schema.json is the introspection result (7.3 MB). admin.types.d.ts holds every type in the schema (4.2 MB). admin.generated.d.ts is the small one, and it describes your operations.

What does a typed query look like?

The call itself does not change. This loader lists variants that are running low:

import type {LoaderFunctionArgs} from 'react-router';

import {authenticate} from '../shopify.server';

export async function loader({request}: LoaderFunctionArgs) {
  const {admin} = await authenticate.admin(request);

  const response = await admin.graphql(
    `#graphql
    query LowStock($query: String!) {
      productVariants(first: 50, query: $query) {
        nodes {
          id
          sku
          inventoryQuantity
          product {
            title
          }
        }
      }
    }`,
    {variables: {query: 'inventory_quantity:<5'}},
  );
  const {data} = await response.json();

  return (data?.productVariants.nodes ?? []).map((variant) => ({
    id: variant.id,
    sku: variant.sku ?? 'no SKU',
    left: variant.inventoryQuantity ?? 0,
    title: variant.product.title,
  }));
}

data is no longer any. Reading a field the query did not select fails the build with Property 'handle' does not exist on type 'Pick<Product, "title">'. A misspelt variable fails too: 'search' does not exist in type '{ query: string; }'.

Nullability comes from the schema. Remove the ?? 'no SKU' and TypeScript reports 'variant.sku' is possibly 'null' or 'undefined', which is correct, because sku is nullable in the Admin API.

Custom scalars are typed as string. Money, Decimal, DateTime and UnsignedInt64 all come through that way, and JSON is unknown, so parsing them is still your job.

Why do the generated types fall back to any?

The answer is in admin.generated.d.ts. It declares an interface keyed by your query strings, whitespace included, and merges that interface into the client package. The key is shortened here; the real one is the whole query:

interface GeneratedQueryTypes {
  "#graphql\n    query LowStock($query: String!) {\n ...": {return: LowStockQuery, variables: LowStockQueryVariables},
}

declare module '@shopify/admin-api-client' {
  type InputMaybe<T> = AdminTypes.InputMaybe<T>;
  interface AdminQueries extends GeneratedQueryTypes {}
  interface AdminMutations extends GeneratedMutationTypes {}
}

admin.graphql() looks up the literal type of the string you pass. A match gives you types. A miss gives you any, and TypeScript says nothing about the miss itself. We found five ways to miss.

The query changed and codegen was not run again. Reindenting is enough: we moved the query LowStock line two spaces to the right and the lookup failed. Under strict the loader above then stops with Parameter 'variant' implicitly has an 'any' type, because of the .map() callback. Code that only reads properties, such as data.anything.atAll, compiles without complaint.

The operation has no name. An anonymous query on its own is skipped: codegen exits 0 and writes nothing for it. Alongside a named operation the run fails with This anonymous operation must be the only defined operation.

The string has no #graphql marker. A /* GraphQL */ comment in front of the template literal also counts, but an unmarked string is never read. If no file has a marked one, the run stops with Unable to find any GraphQL type definitions for the following pointers.

The query lives in a .graphql file. Shopify’s guide rules it out: “Parsing will not work on .graphql documents, because the preset can only apply types from JavaScript and TypeScript const strings.”

The fifth depends on your package manager. The generated file augments @shopify/admin-api-client by name. In a pnpm 12.21.0 project that listed only @shopify/shopify-app-react-router, that package could not be resolved from app/types, so the declaration merged into nothing. Every response stayed any, and TypeScript reported no error in the generated file even with skipLibCheck off. pnpm add @shopify/admin-api-client fixed it. Leaving app/types out of the include list in tsconfig.json has the same effect.

What does codegen not check?

variables is optional in the client’s types. Passing {variables: {}} is an error (Property 'query' is missing in type '{}'), but leaving the options argument off altogether compiles, even though $query is declared String!. The missing variable only surfaces as a GraphQL error when the request runs.

The version in .graphqlrc.ts and the apiVersion you pass to shopifyApp() in shopify.server.ts are separate settings, and nothing compares them. Types generated from 2026-10 will describe responses fetched from 2026-07 without objection. Change both in the same commit.

Deprecations pass silently. The automaticDiscounts reference for 2026-10 reads “Deprecated. Use automaticDiscountNodes instead. This will be removed in 2027-01.” A query that uses it generated types with no warning.

Can codegen rehearse the next API version?

Yes, because removals are not silent. 2027-01 is the release candidate until it becomes stable on 1 January 2027, according to Shopify’s versioning page. Change apiVersion to '2027-01', run codegen, and that same query now fails:

Error 0: Cannot query field "automaticDiscounts" on type "QueryRoot". Did you mean "automaticDiscount", "automaticDiscountNode", "automaticDiscountNodes", or "locationsCount"?

Every marked query in the app is validated against the new schema this way, without a request to a store. Use the plain string for the version, because the ApiVersion enum in @shopify/shopify-api 15.1.2 has no release candidate entry. Its newest dated member is October26.

Watch the schema file while you do this. If admin-2027-01.schema.json already exists in app/types, the preset reads it instead of fetching a fresh copy, and Shopify says a release candidate “May include backwards-incompatible changes”. Delete the file before each rehearsal. The schema is only one part of an upgrade; our quarterly API version routine covers the webhook version pin and the API health report.

How do you stop the types going stale in CI?

Commit all three generated files and run codegen in dry-run mode:

npm run graphql-codegen -- --check

It exits 1 and prints The following stale files were detected: when the files on disk differ from what it would write. That caught the reindented query from earlier. It also reports the schema JSON as stale when that file is missing, so you cannot gitignore the 7 MB file and keep --check. If you would rather not commit it, run plain codegen in CI and fail the job on git diff --exit-code app/types/admin.generated.d.ts.

We would switch this on in any TypeScript Shopify app, and we would not do it without the CI check. Generated types that can go stale are worse than an honest any, because the code reads as if it had been checked. The exception is an app that assembles its queries at runtime. There is no fixed string to key on, so write those response types by hand.

We build and maintain Shopify apps, including the quarterly version upgrades that go with them. If yours makes untyped Admin API calls and nobody is sure which fields are about to be removed, that is the kind of Shopify development work we take on.

Need this built properly?

Get in touch

Hack the planet!