Skip to content

Instantly share code, notes, and snippets.

@reicheltp
Last active April 25, 2017 21:13
Show Gist options
  • Select an option

  • Save reicheltp/4cc667e15a17fad124b1ddc33865c59f to your computer and use it in GitHub Desktop.

Select an option

Save reicheltp/4cc667e15a17fad124b1ddc33865c59f to your computer and use it in GitHub Desktop.
node-dgraph-mutation.js
let setReq = new Request();
setReq.mutation = new Mutation();
// a string value nquad
let nqName = new NQuad();
nqName.subject = 'paul';
nqName.predicate = 'name';
nqName.objectValue = new Value().set('str_val', 'Paul Reichelt');
nqName.objectType = 10;
// a float value nquad
let nqAge = new NQuad();
nqAge.subject = 'paul';
nqAge.predicate = 'size';
nqAge.objectValue = new Value().set('double_val', 1.85);
nqAge.objectType = 3;
// add all nquads to the request's mutation
setReq.mutation.set.push(nqName);
setReq.mutation.set.push(nqAge);
// execute the request
dgraph.run(setReq, (err, res) => console.log(err || res));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment