【发布时间】:2018-03-11 07:40:39
【问题描述】:
我正在尝试根据搜索关键字获取 Shopify 产品。
我通过在查询中传递硬编码值来测试这个查询,它工作正常,但我需要传递变量值,所以在这种情况下它会给出一个错误
Grapghql 查询错误 searchKeyword 已声明但未使用。
这是我根据title、tag 和product_type 搜索产品的查询。
不成功案例:
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
}
}
}
}
}
}
}
}`;
成功案例:
export const searchProductsQuery = gql` query{
shop {
products(first: 10, query:"title:'games' OR tag:'games' OR product_type:'games'") {
...
};
【问题讨论】:
标签: javascript react-native shopify graphql-js react-apollo