Searching for products with array of product handles using GraphQL

mmkkyweb
New Member
1 0 0

I'm trying to replace all my calls with GraphQL, and so far it's been going quite well. However, that being said, I'm having issues replacing my last call, which is a product search by handle. I know there's a productByHandle as noted here, https://shopify.dev/docs/admin-api/graphql/reference/common-objects/queryroot. However, this only allows me to specify one handle. If I have a bunch of them, what is the best way? The rest API lets me specify comma separated handles so I can search multiple, so I'd like something to replicate that. I guess I could have multiple queries in a mutation, but is that the best way of doing things?

0 Likes
CalD
Shopify Staff
Shopify Staff
129 15 19

Hey @mmkkyweb,

productByHandle is currently the only way, handle is not a supported product query parameter.

You could look into GraphQL aliases to check multiple handles, e.g. with this example query:

{
  testProducts: productByHandle(handle:"test"){
    description
  }
  test2Products: productByHandle(handle:"test2"){
    description
  }
}

You could also consider exporting handles into tags, updating the products with those tags, and then use the tag query parameter.

CalD | Developer Support @ 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

0 Likes