Get success/failure status of mutations in an upsert operation

When running an upsert operation with 1 mutation or more, each having conditions, is there a way to know if a mutation has been successfully executed or not ?

In the body result you have few keys that might help you.

{
  "data": {
    "q": [],
    "code": "Success",
    "message": "Done",
    "uids": {
      "uid(v)": "0x1"
    }
  },
  "extensions": {...}
}

If it creates a new node, the UID from it will appear in the "uids" key.

If it just upsert, it will appear in the "q" key (this key is your query). And the "uids" key will be empty.

Make sure that you don’t use var block in the main query that you need information.

I have some tickets opened about implementing better contextual information about the Upsert Block. But for now, that’s what you got.

Cheers.

I don’t recognize this response format, how do you obtain it ?
n.b I work primarily with the nodejs client

My guess (I can look later) is:

const response = await txn.mutate(mu);
        await txn.commit();

console.log(response);

The api is a bit different, you can do response.getUidsMap() to get assigned uid to new nodes and response.getJson() will give you the payload of the query(ies) you ran.

But re-reading your original reply, I realize that you were referring to the data produce by the two functions I mentioned. And as such what you describe is what I’m already doing.
It gets complicated when performing upserts on multiple entities within the same operation however.

Thanks for your reply anyways :slight_smile:

Any chance you could link to some of those tickets, so that I could track the advancement ?

This one

https://github.com/dgraph-io/dgraph/issues/4048

Closed in favor of Support return response after the Upsert Block done. (Like GraphQL does) · Issue #4653 · dgraph-io/dgraph · GitHub

Which is Support return response after the Upsert Block done. (Like GraphQL does)

And this one

Which is

1 Like

This is what you would get out of Ratel. Your client library may already abstract away the things.

1 Like

Thanks