带参数的graphQL突变产生错误:标量中不允许验证失败的变量

时间:2019-03-20 11:00:59

标签: postgresql graphql graphiql hasura

我使用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数据库类型: thing_uid 是BigInt my_coordinates Geometric type

如果在查询中将变量$ x,$ y和$ z替换为1、2和3,则一切正常。

为什么我在使用参数时查询返回错误?

1 个答案:

答案 0 :(得分:0)

Hasura Discord chan的答案:

my_coordinates列的类型是几何体,是标量类型,因此我们可以如下编写查询

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]}
}