【发布时间】:2022-01-14 18:38:14
【问题描述】:
我正在尝试使用 GraphQL 在多个字段中搜索字符串。
我能够使用带有 or 字段的过滤器功能,但它没有检索任何内容。 我希望能够检索一个数组,其中包含标题或/和正文 ==> 中包含搜索字符串的所有项目,因此如果在标题或正文中找到查询字符串,则将其检索到数组中。
我的代码是:
const search_reviews= gql`
query SearchReviews ($my_query: String) {
reviews (filters: {title: {contains: $my_query}, or: {body: {contains: $my_query}} }) {
data{
id
attributes{
title
rating
body
categories{
data{
id
attributes
{
name
}
}
}
}
}
}
}
`
只适用于一个字段,但我想在两个字段中都有它
const search_reviews= gql`
query SearchReviews ($my_query: String!) {
reviews (filters: {body: {contains: $my_query} }) {
data{
id
attributes{
title
rating
body
categories{
data{
id
attributes
{
name
}
}
}
}
}
}
}
`
【问题讨论】:
标签: graphql graphql-js