Hasura graphql optional generated variable

Hasura graphql optional generated variable


0

how can I attach a variable to a mutation conditionally?
I want to create an upsert mutation where the id is generated by the database.
So, if the $id variable was set, make an update, otherwise, a creation.
I have tried something like this:

  mutation upsert (
    $id: uuid
    $name: String
  ) {
    insert_data_one(
      object: {
        id: $id
        name: $name
      }
     on_conflict: {
      constraint: data_pkey
      update_columns: [name ]
    }
    ) {
      id
      name
    }
  }

But the error I receive is a malformed id

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_data_one.args.object.id",
        "code": "validation-failed"
      },
      "message": "unexpected null value for type "uuid""
    }
  ]
}


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *