Have your say in Community Polls: What was/is your greatest motivation to start your own business?

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

Solved

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

s2seaders
Shopify Partner
2 1 0

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,

s2seaders_0-1731502505036.png

 

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)

 

Accepted Solution (1)

s2seaders
Shopify Partner
2 1 0

This is an accepted solution.

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?

View solution in original post

Reply 1 (1)

s2seaders
Shopify Partner
2 1 0

This is an accepted solution.

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?