A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am trying to filter products within a collection using the Storefront GraphQL API: -
query ($handle: String!, $filters: [ProductFilter!]) { collection(handle: $handle){ products(first: 250, filters: $filters) { edges { node { id handle title descriptionHtml productType tags } } pageInfo { hasNextPage endCursor } } } }
{
"handle": "******",
"filters": [{"tag": "*****"}]
}
Solved! Go to the solution
This is an accepted solution.
After a lot of back-and-forth with technical support, it turns out they don't support filtering collections with a large number of products inside. Since the collection I wanted to filter had 7k products, this was causing the problem. Smaller collections should work fine.
Hi @Richard_Peck,
Thanks for your post. When testing just now in a test store with the Storefront API v2023-04 using the query that you specified all expected products are being returned with different combinations of a collection handle and a tag.
If you're still having trouble with products consistently missing from the query please submit a support request through the Partner dashboard and use the API Support topic and Email path. Important details include a specific example from a store that you have staff or collaborator access to with details of both queries used (the product one as well as the collection one), which App is making the queries, which API version is being used, and a specific product that keeps getting excluded from the results even though it matches the filter.
For the part about tag filtering, if you're looking for an 'AND' type filter on multiple tags setting up the variables this way works:
{
"handle": "test-1",
"filters": [
{
"tag": "skis",
"tag": "Large"
}
]
}
Hope you have a great day,
Jon551
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
Many thanks for the comprehensive response!
Let me send a support request in the partner dashboard. I'll also check your suggestion regarding the tag filters. I am quite sure I did test that but will look again.
I'll provide an update having done so.
Nope, filters not respecting "AND" functionality at all. Will detail it further in partner dashboard support ticket. Thank you for your help.
@Richard_Peck did you find a solution to this you could share? We're hitting the same issue and looking for a non-hack solution.
This is an accepted solution.
After a lot of back-and-forth with technical support, it turns out they don't support filtering collections with a large number of products inside. Since the collection I wanted to filter had 7k products, this was causing the problem. Smaller collections should work fine.
@Richard_Peck Actually, I found this suggestion to work! Maybe an update since this post, but it works on 2023-10 at least.