When running a mutation unable to get the response in JSON

Moved from GitHub dgraph-js/112

Posted by shreyansh-zazz:

I have added comments:

const dgraph = require('dgraph-js');
const dgraphClient = require('../../config/config').dgraph.client;

module.exports = {
  adduser: async (tnxData) => {
    let res;
    const tnx = dgraphClient.newTxn();

    try {
      const mu = new dgraph.Mutation();
      mu.setSetJson(tnxData);

      // trying to get response in JSON for checking if it is success or failure
      res = await (await tnx.mutate(mu)).getJson();
      
      await tnx.commit();
    } catch (e) {
      throw new Error(e);
    } finally {
      await tnx.discard();
    }

    console.log(res);
    return res;
  },
};

Following is the error I am getting:

Error: SyntaxError: Unexpected end of JSON input