A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am using the following graphql bulk operation request to get all products with tag: "TAG1" from a shopify store:
mutation { bulkOperationRunQuery( query: """ { products (first: 250, query: "tag:tag1 OR tag:tag2") { edges { cursor node { id, tags } } pageInfo { hasNextPage } } } """ ) { bulkOperation { id status } userErrors { field message } } }
This request returns the operation id, when it is completed I download the result. However, the result contains one product only whereas there are many products with this "tag1" or "tag2".
Why one product only is returned?
The AND operator works fine however. So it seems that Shopify's GraphQL API does not directly support filtering products using the OR operator for tags in a single query.
Solved! Go to the solution
This is an accepted solution.
Hi Redochkaya,
Shopify's GraphQL API does not support the OR operator within the product filter query. The query is performed in a way that it pulls the products that contain either "tag1" or "tag2", not both.
However, you can use the AND operator to get all products that have both "tag1" and "tag2". The query will return only those products that have both tags.
If you want to get all products that have either "tag1" or "tag2", you will need to perform two separate queries and then merge the results.
Remember to also set the 'first' parameter to a high number if you expect to have more than the default number of products returned by the query. For example, set it to 100 if you want to retrieve up to 100 products. If you have more than 100 products, you will need to implement pagination to retrieve all products.
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
This is an accepted solution.
Hi Redochkaya,
Shopify's GraphQL API does not support the OR operator within the product filter query. The query is performed in a way that it pulls the products that contain either "tag1" or "tag2", not both.
However, you can use the AND operator to get all products that have both "tag1" and "tag2". The query will return only those products that have both tags.
If you want to get all products that have either "tag1" or "tag2", you will need to perform two separate queries and then merge the results.
Remember to also set the 'first' parameter to a high number if you expect to have more than the default number of products returned by the query. For example, set it to 100 if you want to retrieve up to 100 products. If you have more than 100 products, you will need to implement pagination to retrieve all products.
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