Out now! Check out the Poll results: Do you have a Shopify store?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: inventory_policy parameter is ignored in graphql query

inventory_policy parameter is ignored in graphql query

BenjaminAntoni
Shopify Partner
17 0 4

I am running a query, looking for all variants that have 0 or less in stock and have CONTINUE as its inventory policy.

The query is tested and works in all ways but the ignored query.

It does filter by inventory_quantity correctly, but ignores the second query, returning variants both with inventory_policy CONTINUE, and DENY.

I've tried using CONTINUE, continue, or Continue.
I've tried setting the parameter as inventoryPolicy instead of inventory_policy.
I've tried removing the quantity parameter, only querying "inventory_policy:CONTINUE".
The query does return the inventoryPolicy, and its content is either "DENY" or "CONTINUE"

{
productVariants(
	first: 100
	query: "inventory_policy:CONTINUE AND inventory_quantity:<=0"
) {
	nodes {
		inventoryPolicy
		product {
			title
		}
		title
	}
}
}

 

 

Reply 1 (1)

Liam
Community Manager
3108 344 889

Hi Benjamin,

 

Your GraphQL query seems correct in its structure. The productVariants query with the query parameter is the right way to filter product variants based on certain conditions. However, there are a few things to consider:

  1. Exact Match: The query parameter in Shopify's GraphQL API uses a search syntax similar to the one used in the Shopify admin. It's possible that the inventory_policy field doesn't support exact matching in the way you're attempting.

  2. Alternative Approach: If the direct query doesn't work as expected, you might need to fetch the variants based on one condition (e.g., inventory_quantity:<=0) and then filter the results on your server or client side to get only those with inventoryPolicy set to CONTINUE.

  3. Testing: Use tools like Shopify's GraphiQL app to test your queries. This tool provides real-time feedback and auto-suggestions, which can help identify issues.

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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