How to obtain success message from conditional upsert using Dgraph JS gRPC client?

Thanks for sharing it. I gonna answer in parts.

Take this query as an example

The main point to get the right responses from Dgraph, is to never use “var” block if you wanna see what you are doing.

upsert {
  query {
    q(func: eq(email, "user@company1.io")) {
      v as uid
    }
  }

  mutation {
    set {
      uid(v) <email> "user@company1.io" .
      uid(v) <age> "28" .
    }
  }
}

The first time you run it you will get this answer.

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": {
      "q": []
    },
    "uids": {
      "uid(v)": "0x4e22"
    }
  }
}

As you can see, the “uids” field indicates that we have created a new node and it returns us a UID in the “uid (v)” key.

If you run the same query again, it gonna return this

{
  "data": {
    "code": "Success",
    "message": "Done",
    "queries": {
      "q": [
        {
          "uid": "0x4e22"
        }
      ]
    },
    "uids": {}
  }
}

As you can see, the “uids” field is empty and now we have a response in the “queries” field. This indicates that a new node was not created. “0x4e22” is the node that has the email “user@company1.io”.

For now, that’s the behavior you have to pay attention to.

See this issue to understand what happened in that context.
https://github.com/dgraph-io/dgraph/issues/4048

Also, follow this