You can read the response to mutate with .toObject(), getJson() only works for queries (I believe):
const response = await txn.mutate(mu);
await txn.commit();
const uid = response.toObject().uidsMap[0][n]; # where you'd have to figure out what n you want
# -or -
const uid = response.getUidsMap().get('blank-0'); # or whatever uid you need
In Dgraph playground the ratle UI, if we make any mutation we get a response in JSON tab which contains some useful information like if it was a success or not following is an image
Ratel uses dgraph-js-http that’s why the response structure is different. @shreyansh-zazz have you tried running the dgraph-js example against your server? Did it work?
I’ll ask someone who’s maintaining dgraph-js to take a look at this issue.
getJson() is meant for queries, which can be either from query function or doRequest function. And the mutate function internally makes use of doRequest function.
The response that you see in ratel is from dgraph-js-http client which uses Dgraph’s HTTP endpoint, while dgraph-js repository uses the gRPC endpoint. The getJson() function is useful for the upsert operation with queries using doRequest function.
Nice catch on the exception. I agree that it could be handled better.