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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

GraphQL: Query product by product handle - exact match.

GraphQL: Query product by product handle - exact match.

LukeDavid
Tourist
7 0 1

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
Tourist
7 0 1

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
112 7 76

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
  } 
}