What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

AND filters graphql product

AND filters graphql product

david337
Tourist
9 1 1
      products(
        filters: [{tag:"Black"},{tag:"White"}],
      ) {
...
}

the graphql API supports searching by tag, but this particular query seems to be fetching the products that have the tag Black and products that have the tag White. Given that products can have multiple tags, I wanted this to only fetch the products that have BOTH the Black and White tags. Is it possible?
Replies 2 (2)

Liam
Community Manager
3108 344 895

Hi David,

 

To fetch products that have both the "Black" and "White" tags, you need to implement a more nuanced query strategy, as the direct AND operation for tags through a single query isn't natively supported by the API in the way filters are used in your example. One option would be to perform the initial query to fetch products with either tag, then filter the results in your application code to retain only those items that have both tags. 

 

 

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

david337
Tourist
9 1 1

Hi there. Thank you for the answer.

While this works, I wouldn't really say it's optimal. Shopify should really add this to their backlog.

Kind regards.

David