Field 'category' doesn't exist on type 'Product' with Direct API Access

Topic summary

A developer encountered an error when querying the category field on Shopify’s Product type through direct API access, despite the same GraphQL query working correctly in GraphiQL and server-side admin calls.

Root Cause Identified:
The issue stems from API versioning. The category field wasn’t available in earlier Product definitions (e.g., 2024-01 version). Direct API access was defaulting to an older API version that predates the category field.

Resolution:
Updating the API version in the direct access call to the latest version resolved the problem. The developer confirmed success after explicitly versioning the graphql.json endpoint to use the current API version.

Key Takeaway:
When using direct API access, explicitly specify the API version to ensure access to newer fields and avoid discrepancies with GraphiQL or admin SDK calls, which may default to more recent versions.

Summarized with AI on November 4. AI used: claude-sonnet-4-5-20250929.

Simple enough graphQL query,

{
  products(first: 10) {
    nodes {
      id
      title
      category {
        name
      }
      status
      tracksInventory
      totalInventory
      productType
      featuredMedia {
        preview {
          image {
            url
          }
        }
      }
    }
  }
}

Which works fine with GraphiQL,

But fails through a direct api access call. If I remove category, it also works fine.

The same graphQL also works fine through a server-side admin call,

const { admin } = await shopify.unauthenticated.admin(shop)
    const resp = await admin
      .graphql(/* GraphQL */ `
        {
          products(first: 10) {
            nodes {
              id
              title
              category {
                name
              }
              status
              tracksInventory
              totalInventory
              productType
              featuredMedia {
                preview {
                  image {
                    url
                  }
                }
              }
            }
          }
        }
      `)
      .then((res) => res.json())

    console.log(resp)

Only place it fails strangely, by category not being on a product is with direct api access,

const res = await fetch("shopify:admin/api/graphql.json", {
      method: "POST",
      body: JSON.stringify({
        query: `{
          products(first: 10) {
            nodes {
              id
              title
              category {
                name
              }
              status
              tracksInventory
              totalInventory
              productType
              featuredMedia {
                preview {
                  image {
                    url
                  }
                }
              }
            }
          }
        }`
      })
    })
    const response = await res.json()
    console.log(response)

Just thought about versions here, and, sure enough, category wasn’t in an earlier definition of Product, https://shopify.dev/docs/api/admin-graphql/2024-01/objects/Product

So, I tried to version the graphql.json to the latest,

s2seaders_0-1731518010944.png

and? It’s worked.

Seems like the documented direct access is using the old api? 2024-01 looks like?