在hasura-graphql中可以将运算符作为变量/参数传递

时间:2020-11-03 08:30:55

标签: graphql hasura

我有一个要求,根据输入,我需要两个运算符(_and和_or)。

那么在hasura graphql中可以将运算符作为变量/参数传递吗?

我正在传递“匹配”变量,要求是我应该能够基于单击来传递“ _或”或“ _和”,如果可能的话,请写下操作员的“类型”。

query Search($match: String) {
  restaurants(where: {_or: [{cuisine: {_ilike: $match}}, {name: {_ilike: $match}}]}) {
    cuisine
    id
    name
    reviews {
      body
    }
  }
}
#variable
{
  "match":"%woodland%"
}

1 个答案:

答案 0 :(得分:3)

您可以根据需要构造整个对象; 您可以执行以下操作:

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%"
        }
      }
    ]
  }
}
相关问题