2

I use Hasura and a PostGres DB. Here is the GraphQL mutation

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

Query variables

{
  "thing_uid": 1744,
  "x": 2,
  "y": 3,
  "z": 4
}

And here is the query response

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_conf_thing.args.objects[0].my_coordinates",
        "code": "validation-failed"
      },
      "message": "variables are not allowed in scalars"
    }
  ]
}

Postgres DB types : thing_uid is a BigInt my_coordinates is a Geometric type

If I replace the variables $x, $y and $z by 1, 2 and 3 in the query, everything works fine.

Why the query returns an error when I'm using parameters ?

Sèb
  • 471
  • 2
  • 7
  • 17

1 Answers1

1

Answer from the Hasura Discord chan :

The type of my_coordinates column is geometry, a scalar type, so we can write the query as follows

mutation submitBeacon($id: bigint, $geometry: geometry) {
  insert_conf_test(objects: {aBigInt: $id, aGeometry: $geometry}){
    returning{
      aBigInt
      aGeometry
    }
  }
}

With the query variables

{
"id": 4,
"geometry": {"type": "Point", "coordinates": [1, 2, 3]}
}
Sèb
  • 471
  • 2
  • 7
  • 17