我有一个要求,需要根据输入使用两个运算符(_and 和 _or)。
那么是否可以在 hasura graphql 中将运算符作为变量/参数传递?
我正在传递“match”变量,要求是我应该能够根据一些点击传递“_or”或“_and”,如果可能的话,请写下运算符的“类型”。
query Search($match: String) {
restaurants(where: {_or: [{cuisine: {_ilike: $match}}, {name: {_ilike: $match}}]}) {
cuisine
id
name
reviews {
body
}
}
}
#variable
{
"match":"%woodland%"
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以根据您的需要构建整个 where 对象;你可以这样做:
query($match: restaurants_bool_exp!) {
restaurants(where: $match) {
id
name
cuisine
reviews {
body
}
}
}
Run Code Online (Sandbox Code Playgroud)
#变量_1
{
"match": {
"_or": [
{
"name": {
"_ilike": "%user entered value%"
}
},
{
"cuisine": {
"_ilike": "%user entered value%"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
#变量_2
{
"match": {
"_and": [
{
"name": {
"_ilike": "%user entered value%"
}
},
{
"cuisine": {
"_ilike": "%user entered value%"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
755 次 |
| 最近记录: |