是否可以在 hasura-graphql 中将运算符作为 variable/parameter 传递
Is is possible to pass operator as variable/parameter in hasura-graphql
我有一个要求,我需要两个基于输入的运算符(_and 和 _or)。
那么可以在 hasura graphql 中将运算符作为 variable/parameter 传递吗?
我正在传递“匹配”变量,要求是我应该能够根据某些点击传递“_or”或“_and”,如果可能的话,请记下运算符。
query Search($match: String) {
restaurants(where: {_or: [{cuisine: {_ilike: $match}}, {name: {_ilike: $match}}]}) {
cuisine
id
name
reviews {
body
}
}
}
#variable
{
"match":"%woodland%"
}
可以根据自己的需要构造整个where对象;
你可以这样做:
query($match: restaurants_bool_exp!) {
restaurants(where: $match) {
id
name
cuisine
reviews {
body
}
}
}
#variables_1
{
"match": {
"_or": [
{
"name": {
"_ilike": "%user entered value%"
}
},
{
"cuisine": {
"_ilike": "%user entered value%"
}
}
]
}
}
#variables_2
{
"match": {
"_and": [
{
"name": {
"_ilike": "%user entered value%"
}
},
{
"cuisine": {
"_ilike": "%user entered value%"
}
}
]
}
}
我有一个要求,我需要两个基于输入的运算符(_and 和 _or)。
那么可以在 hasura graphql 中将运算符作为 variable/parameter 传递吗?
我正在传递“匹配”变量,要求是我应该能够根据某些点击传递“_or”或“_and”,如果可能的话,请记下运算符。
query Search($match: String) {
restaurants(where: {_or: [{cuisine: {_ilike: $match}}, {name: {_ilike: $match}}]}) {
cuisine
id
name
reviews {
body
}
}
}
#variable
{
"match":"%woodland%"
}
可以根据自己的需要构造整个where对象; 你可以这样做:
query($match: restaurants_bool_exp!) {
restaurants(where: $match) {
id
name
cuisine
reviews {
body
}
}
}
#variables_1
{
"match": {
"_or": [
{
"name": {
"_ilike": "%user entered value%"
}
},
{
"cuisine": {
"_ilike": "%user entered value%"
}
}
]
}
}
#variables_2
{
"match": {
"_and": [
{
"name": {
"_ilike": "%user entered value%"
}
},
{
"cuisine": {
"_ilike": "%user entered value%"
}
}
]
}
}