I'm trying to fetch Shopify products on the basis of search keyword.
I tested this query by passing hard coded value in the query it works fine but I need to pass variable value so in that case it gives an error that
Grapghql query error searchKeyword is declared but not used.
Here is my query to search products on the basis of title, tag and product_type.
Unsuccessful case:
export const searchProductsQuery = gql` query($searchKeyword: String!){
shop {
products(first: 10, query:"title:'$searchKeyword' OR tag:'$searchKeyword' OR product_type:'$searchKeyword'") {
edges {
cursor
node {
id
title
handle
description
productType
images(first: 5) {
edges {
node {
id
src
}
}
}
variants(first: 5) {
edges {
node {
id
title
price
}
}
}
}
}
}
}
}`;
Successful case:
export const searchProductsQuery = gql` query{
shop {
products(first: 10, query:"title:'games' OR tag:'games' OR product_type:'games'") {
...
};