From 1d67f1649484b820025488ef23a14680e7ca6766 Mon Sep 17 00:00:00 2001 From: Sai Boorlagadda Date: Fri, 19 Jan 2018 09:50:40 -0800 Subject: [PATCH] Added a way to retrieve returned UIDs from a mutation --- examples/simple/index-pre-v7.6.js | 7 +++++-- examples/simple/index.js | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/simple/index-pre-v7.6.js b/examples/simple/index-pre-v7.6.js index 5eb5f06..4110b56 100644 --- a/examples/simple/index-pre-v7.6.js +++ b/examples/simple/index-pre-v7.6.js @@ -71,9 +71,12 @@ function createData(dgraphClient) { // Run mutation. const mu = new dgraph.Mutation(); mu.setSetJson(serialized); - return txn.mutate(mu).then(() => { + return txn.mutate(mu).then((assigned) => { // Commit transaction. - return txn.commit(); + txn.commit(); + console.log("Mutation is successful and here are the generated UIDs......"); + assigned.getUidsMap().forEach((value, key) => console.log("UID for key: " + key + ", value: " + value)); + return; }).catch((e) => { err = e; }).then(() => { diff --git a/examples/simple/index.js b/examples/simple/index.js index 4fed71d..609410d 100644 --- a/examples/simple/index.js +++ b/examples/simple/index.js @@ -70,8 +70,9 @@ async function createData(dgraphClient) { // Run mutation. const mu = new dgraph.Mutation(); mu.setSetJson(serialized); - await txn.mutate(mu); - + let assigned = await txn.mutate(mu); + console.log("Mutation is successful and here are the generated UIDs......"); + assigned.getUidsMap().forEach((value, key) => console.log("UID for key: " + key + ", value: " + value)); // Commit transaction. await txn.commit(); } finally {