A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi, I want to get all product variants with full inventory items. I try to get the quantities in inventoryItem, but I get errors: Field 'quantities' doesn't exist on type 'InventoryLevel'. Please help me resolve this problem. Thank you so much.
My graphQL code
query InventoryItems( \$limit: Int!, \$cursor: String, \$query: String, \$locationId: ID! ) { productVariants (first: \$limit, after: \$cursor) { edges { node { id title displayName image { url } inventoryItem { id sku inventoryLevel(locationId: \$locationId) { id quantities (names: "available") { quantity name } } } product { id hasOnlyDefaultVariant title featuredImage { id url altText } } } cursor } pageInfo { hasNextPage endCursor } } }
Solved! Go to the solution
This is an accepted solution.
Hey @TuyenND,
Great question here. Over time, the fields and connections available on an object may be updated or deprecated between API versions, which may explain the error returned.
Our API docs are always a good starting point, and in this case the InventoryLevel object docs only have the data you are looking for available in versions 2023-01 and newer. When a root query or connection supports returning InventoryLevel data and is supplied with a locationId argument, the quantity and name fields can be returned like in the example query shared above. When toggling back through older versions, you will notice that these fields didn't exist in prior versions.
I have put together an example query that I used to test this, that has been slightly simplified for readability in the thread. In all tests, it is returning results as expected:
GraphQL Body:
query VariantQuantityByLocation($locationId: ID!) {
productVariants(first: 5) {
nodes {
id
title
inventoryItem {
id
inventoryLevel(locationId: $locationId) {
id
quantities(names: "available") {
quantity
updatedAt
}
}
}
}
}
}
Variables:
{
"locationId": "gid://shopify/Location/LOCATION_ID"
}
Hope the example and linked docs help shed some light on the error - Cheers!
@awwdam
Shopify Developer Support
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hey @TuyenND,
Great question here. Over time, the fields and connections available on an object may be updated or deprecated between API versions, which may explain the error returned.
Our API docs are always a good starting point, and in this case the InventoryLevel object docs only have the data you are looking for available in versions 2023-01 and newer. When a root query or connection supports returning InventoryLevel data and is supplied with a locationId argument, the quantity and name fields can be returned like in the example query shared above. When toggling back through older versions, you will notice that these fields didn't exist in prior versions.
I have put together an example query that I used to test this, that has been slightly simplified for readability in the thread. In all tests, it is returning results as expected:
GraphQL Body:
query VariantQuantityByLocation($locationId: ID!) {
productVariants(first: 5) {
nodes {
id
title
inventoryItem {
id
inventoryLevel(locationId: $locationId) {
id
quantities(names: "available") {
quantity
updatedAt
}
}
}
}
}
}
Variables:
{
"locationId": "gid://shopify/Location/LOCATION_ID"
}
Hope the example and linked docs help shed some light on the error - Cheers!
@awwdam
Shopify Developer Support
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
LOL!!!! How in in the world are we supposed to know what the possible values of "names" are? Names? That actually makes sense to you and it's supposed to make sense to us when there is absolutely no documentation on the possible value of "names"? "available" is a status. It is not a name. This is where English is so important. Please tell us all where you have ever known anyone, anything, or anyplace with the name "available".
Gotta admit this is pretty stupid.
Only way for most people to know what the names are is accessing the quantity fields.
Which you can't access without the names.
At least update the documentation. Better even, remove the requirement on the argument, I'm pretty sure it's not even needed.
Hey @Eliazar and @Schmidtc63 !
Thanks for sharing that feedback. It definitely would make a little more sense to have it as a "status" or something similar to better represent the field as opposed to a name. I have passed this on to our product teams to update the documentation, and to consider even removing the requirement of the argument for the InventoryProperties.
-Kyle G
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog