GraphQL: Query product by product handle - exact match.

LukeDavid
New Member
7 0 0

I'm having issues being able to find a way to query by a product handle returning an exact match

The following returns any product that has "vista-pro-60" in any searchable field.

 

{
  products(first: 1, query: "'vista-pro-60'") {
    edges {
      node {
        id
        handle
        title
        tags
        productType
        vendor
      }
    }
  }
}

 

 

According to the graphQL docs on Shopify the product handle is not listed. This seems like a mistake to me. Am I missing something?

I've also tried the following just to be sure they didn't accidentally leave it off the docs:

 

products(first: 1, query: "handle: 'vista-pro-60'")

 

 

Any insight or help would be greatly appreciated.

Replies 3 (3)

LukeDavid
New Member
7 0 0

Found a non graphQL solution. I updated the graphQL to 

products(first: 10, query: "'vista-pro-60'")

 

And then filtered down the response to the node that was an exact match.

tolgapaksoy
Shopify Partner
105 7 64

There is a specific query for this:

query ($handle: String!) {
  productByHandle(handle: $handle) {
    id
    handle
    title
    tags
    productType
    vendor
  }
}

 

BogdanOasa
Shopify Partner
6 0 4

productByHandle is deprecated, use this instead:

{
  product(handle:"{{handle}}") {
      title
  } 
}