FROM CACHE - en_header

"Field 'inventoryItem' doesn't exist on type 'ProductVariant'"

jacksonvaughn
New Member
1 0 0

I am trying to write some code to get a product variant's current inventory and then update that same inventory. I am using the storefront graphql API (/api/2021-01/graphql) for the ProductVariant object.

I am able to run the query correctly, but only when using certain fields like id, price, image, etc. But there are some other fields featured in the docs that return an error message saying the field does not exist.

My currently functional query is:

const query = () => `{
node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTUxMDg1MTQyMDI3NQ==") {
  ... on ProductVariant {
    id
    title
  }
}`;

That works fine, but when I try to add the 'inventoryQuantity' field (which does appear as a featured field on the docs) I get the following error:
"Field 'inventoryQuantity' doesn't exist on type 'ProductVariant'"

That when running the following code:
const query = () => `{
  node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8zMTUxMDg1MTQyMDI3NQ==") {
    ... on ProductVariant {
      id
      title
      inventoryQuantity
    }
  }
}`;

The docs I am using are https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/productvariant?api%5Bv...

Any idea why?

Thanks!

Replies 2 (2)
c10s
Shopify Partner
67 12 16

The Storefront API doesn't have the same access to everything the Admin API does, which are the docs that you linked to.

Here's what's available for product variants with the Storefront API: https://shopify.dev/docs/storefront-api/reference/products/productvariant#fields-2021-01

shopadev
New Member
1 0 0

OP's link is for the admin graphQL API. I don't understand your response. I'm also having the same issue trying to get priceV2 from a variant node through the ADMIN graphQL API (2021-04) but certain fields come back with errors stating that the field is not available.