"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!

0 Likes
c10s
Shopify Partner
15 2 3

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

0 Likes