GraphQL search for products based on description

Solved
New Member
3 0 0

Is there anyway to use graphQL to search for products with a description that contains a string. I tried this, but it does not work.

 

{
  products(query:"description:*Black*" first:5 ) {
    edges {
      node {
        id
        title
        description
      }
    }
  } 
}
0 Likes

Success.

Shopify Staff
Shopify Staff
299 32 59

Hey there,

 

The GraphQL docs show what filter parameters you can use when querying products.

 

Unfortunately, `description` isn't an option, but you can use the product `title` or `tag` amongst a list of other properties.

1 Like
Tourist
7 2 0

I was so happy when I searched the community and saw that someone had the exact same question that I am struggling with right now, and there was an answer. 

 

But when I went to the link provided, :( I feel more sad than ever, because I do not understand how to implement the solution AT. ALL. 

 

I already know that the "products" object has within it, the properties, for example, of "title", "vendor" that I want to be able to use as variables in queries. 

 

But the query I have is written like this: 

 products(first: 20, query: here?) {
    edges {
      node {
        title
        description
      }
    }
  }

I don't understand where the query goes inside the query??? How do you write it? There's a list of supported filter parameters, but what about the other product attributes? Just one example would have been nice... 

 

Sorry, just frustrated... :(  I tried lots of different ways but nothing works. 

 

This page and this page are just mocking me at this point. I know *what*, I just don't know *how*. And they shouldn't title that one page "Syntax" when nowhere anywhere on the whole page does it show any examples of how to actually use it in a functional use case. There is no larger context whatsoever.

 

0 Likes
Shopify Staff
Shopify Staff
299 32 59

 

Hey @ACrego ,

 

When using the `query` parameter in GraphQL there are a few things to keep in mind.

 

First, the statement needs to be a string. Second, you use one of the supported `filter parameters` shown in the GraphQL object documentation. Third, you use one of the `comparators` shown in the Search Syntax documentation. Lastly, you follow it with whatever value you're interested in looking for.

 

As an example, if you wanted to find the ids and titles of all the products in your store that included the word `Shirt` in the title, you would have:

{
  products(first: 20, query: "title:Shirt") {
    edges {
      node {
        id
        title
      }
    }
  }
}

If instead, you wanted to find the ids and descriptions of all the products in your store that exactly matched the `Plaid Shirt` title, you would have:

{
  products(first: 20, query: "title:'Plaid Shirt'") {
    edges {
      node {
        id
        description
      }
    }
  }
}

This can then be combined with additional logical terms such as AND, or OR to make more complex queries. You can also use prefix queries with `*` that allows you to search for products that begin with a certain string. 

 

Hopefully, this helps you configure the queries you're looking for!

0 Likes