AND filters graphql product

AND filters graphql product

david337
Tourist
9 1 0
      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
Shopify Staff
2862 312 813

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 0

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