Using GraphQL variables in upsert mutations

I was trying to use GraphQL variables, like I would for a GraphQL+/- query, but with an upsert. And it seems there is a bug that makes it not work - don’t know if this is by design or not.

The JSON I am sending to the mutation API -

  query: "query GetNode($name:string!) {
    node(func:type("Node")) @filter(eq(name,$name)) { nodeuid as uid }
  set: [{
    "dgraph.type": "Node",
    "uid": "uid(nodeuid)",
    name: "$name"
  variables: { "$name": "very special" }

So there are a couple of problems with this,

  1. The “variables” section is not being passed into the query - the value of $name is empty.
  2. The appearance of $name inside the set [ {} ] doesn’t work
  3. The query can accept variables, as default parameters query GetNode($name:string = "special") works.
  4. But the “mandatory” variable does not work with default parameters, so query GetNode($name:string! = "special") throws an error.

It’s not exactly a bug, it’s just not supported. - Upsert Block is a too new feature. It will take a while before it has all the possible features that exist in GraphQL+-. See, an easy way to know if it will work is through the documentation. If it is not documented, it has a 90% chance of not being supported. Another way is “digging the code” or asking.

You can follow this issue

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.