【问题标题】:graphQL mutation with parameters gives error : validation failed variables are not allowed in scalars带有参数的graphQL突变给出错误:标量中不允许验证失败的变量
【发布时间】:2019-08-11 01:17:26
【问题描述】:

我使用 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_coordinatesGeometric type

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

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

【问题讨论】:

  • 你在后端使用 Hasura 吗?
  • 是的,我愿意。我会把它添加到描述中。

标签: postgresql graphql graphiql hasura


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-10-18
    • 1970-01-01
    • 2018-07-14
    • 2020-05-23
    • 2022-11-19
    • 2017-12-26
    • 2016-02-16
    • 2021-05-20
    • 1970-01-01
    相关资源
    最近更新 更多