postgresql - 带有参数的graphQL突变给出错误:标量中不允许验证失败的变量
问题描述
我使用 Hasura 和 PostGres 数据库。这是 GraphQL 突变
mutation submitBeacon($thing_uid: Int, $x: Int, $y: Int, $z: Int){
insert_conf_thing(objects:
[{thing_uid: $thing_uid, my_coordinates: {type: "Point", coordinates: [$x, $y, $z]}}]) {
returning {
thing_uid
my_coordinates
} } }
查询变量
{
"thing_uid": 1744,
"x": 2,
"y": 3,
"z": 4
}
这是查询响应
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.insert_conf_thing.args.objects[0].my_coordinates",
"code": "validation-failed"
},
"message": "variables are not allowed in scalars"
}
]
}
Postgres DB 类型: thing_uid是 BigInt my_coordinates是Geometric 类型
如果我在查询中将变量 $x、$y 和 $z 替换为 1、2 和 3,则一切正常。
为什么当我使用参数时查询返回错误?
解决方案
Hasura Discord chan的回答:
my_coordinates 列的类型是geometry,是标量类型,所以我们可以这样写查询
mutation submitBeacon($id: bigint, $geometry: geometry) {
insert_conf_test(objects: {aBigInt: $id, aGeometry: $geometry}){
returning{
aBigInt
aGeometry
}
}
}
使用查询变量
{
"id": 4,
"geometry": {"type": "Point", "coordinates": [1, 2, 3]}
}
推荐阅读
- vim - 如何在 Vim 中列出 autocmd 组?
- angular - 如何解决 Ionic Angular 应用程序中的 CORS 策略问题?
- vba - 确定夏令时是否对 VBA 中的特定时区有效
- java - 在 oracle SQL 中正确排序分页结果
- netsuite - 将供应商付款应用于 NetSuite 中的费用报告
- android - 如果数据类的属性符合接口的属性的接口,为什么它不能符合接口?
- html - 如何在角度 8 中获取对象内的第一个对象
- fortran - 有没有办法在 fortran 中读取文件的一部分?
- r - R:尝试用特定条件的值填充一列
- javascript - 如何使用 Hooks 从一个组件到另一个组件的链接(href),从导航栏传递到我的组件?