graphql - 是否可以在 hasura-graphql 中将运算符作为变量/参数传递
问题描述
我有一个要求,我需要基于输入的两个运算符(_and 和 _or)。
那么是否可以在 hasura graphql 中将运算符作为变量/参数传递?
我正在传递“匹配”变量,要求是我应该能够根据一些点击传递“_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%"
}
}
]
}
}
推荐阅读
- html - 未调用 Gmail 电子邮件标记
- r - 未能省略包含 NA 值的列:na.rm=TRUE 和 na.action=NULL
- javascript - 有没有办法拦截 Web 浏览器中 JavaScript 发出的所有网络请求?
- oracle - PL/SQL how to get result from a function that returns type table of
- angular - Angular 6 - 浏览器刷新页面 id 丢失
- python - 无法从 opencv 转换为 PIL Image 以正确输入到自定义模型( InceptionV3 )
- javascript - 在浏览器中,如何检测与按钮交互触发了什么事件?
- spring - 我的 authenticationTokenFilterBean 在非受保护端点上被调用
- google-sheets - 谷歌表格 IMPORTXML 的价格
- git - 如何将下载的 ZIP 项目从 bitbucket 推送到 Github?