Meaning of operation return value

I’m using dgraph-js with node. When performing an operation such as a schema update, I want to send back some sort of acknowledgement indicating the success or failure of the operation. In case of success, I’d like to send back something meaningful, such as echoing back the updated schema.

I’m playing around with the return value of dgraphClient.alter(), but as far as I can tell, it’s mostly unintelligible:

{
    "wrappers_": null,
    "arrayIndexOffset_": -1,
    "array": [],
    "pivot_": 1.7976931348623157e+308,
    "convertedFloatingPointFields_": {}
}

Any suggestions on how to improve the response? The code I’m using looks something like

export async function initDatabase() {
  const schema = `
    name: string @index(fulltext) .
    email: string @index(exact) .
    uuid: string @index(exact) .
  `;
  const op = new dgraph.Operation();
  op.setSchema(schema);
  const result = await dgraphClient.alter(op);
  return result
}

Try like this https://github.com/MichelDiz/apollo-universal-starter-kit-With-Dgraph-DB/blob/86160bae53595290703221192f1b7a405ae8bc38/packages/server/src/dgraph/dgraphconnector.js#L97

Thanks for the quick reply Michel! Not sure that quite answers the question. I wasn’t necessarily looking for an answer in code, but in any case, the code you link to never deals with the return value of alter(op). What I’m trying to understand is if there’s any useful information there that can be sent back to the client.

If you use |line 13 |===> dgraphClient.setDebugMode(true); , you will receive this response

Alter response:
{"data":""}

Otherwise it will return an error.

1 Like

Thanks for the clue. I found what I was looking for in toObject():

  const result = await dgraphClient.alter(operation);
  return result.toObject()