setSetJson() does not support named blank nodes

Moved from GitHub dgraph-js/59

Posted by jpstrikesback:

I’m getting errors when running a mutation with a named blank node via the dgraph-js client (same works in ratel)

  uid: '_:somename',
  description: 'Describe thing',
  aDate: '2019-07-02T04:00:00.000Z'
  error: Error: 2 UNKNOWN: strconv.ParseUint: parsing "_:somename": invalid syntax
      at Object.exports.createStatusError (/node_modules/grpc/src/common.js:91:15)
      at Object.onReceiveStatus (/node_modules/grpc/src/client_interceptors.js:1204:28)
      at InterceptingListener._callNext (/node_modules/grpc/src/client_interceptors.js:568:42)
      at InterceptingListener.onReceiveStatus (/node_modules/grpc/src/client_interceptors.js:618:8)
      at callback (/node_modules/grpc/src/client_interceptors.js:845:24) {
    code: 2,
    metadata: Metadata { _internal_repr: {} },
    details: 'strconv.ParseUint: parsing "_:somename": invalid syntax'

this adds a bunch of impedance when writing dependant mutations…

MichelDiz commented :

Are you parsing the obj to JSON? it’s not clear from your example.

This should be the valid JSON.

	"uid": "_:somename",
	"description": "Describe thing",
	"aDate": "2019-07-02T04:00:00.000Z"

Also, from your test is it working without blank nodes?

jpstrikesback commented :

Thanks for the fast response!

It is sent just like in the examples (if I send a pure JSON string it chokes of course).

    const node = {
      uid: '_:somename',
      description: 'Describe thing',
      aDate: '2019-07-02T04:00:00.000Z'
    const mutation = new dgraph.Mutation();
    const done = await txn.mutate(mutation);

If I leave the uid field out the blank nodes come back fine via done.getUidsMap().get('blank-0')

MichelDiz commented :

I’ve did a quick test here and your example is working normally. I thought you were doing something else.

BTW - Ratel uses the HTTP API not any JS client.

const dgraph = require("dgraph-js");

// Create a client stub.
function newClientStub() {
    return new dgraph.DgraphClientStub("localhost:9080");

// Create a client.
function newClient(clientStub) {
    return new dgraph.DgraphClient(clientStub);

async function createData(dgraphClient) {
    // Create a new transaction.
    const txn = dgraphClient.newTxn();
    try {
        // Create data.
        const p = {
            uid: '_:somename',
            description: 'Describe thing',
            aDate: '2019-07-02T04:00:00.000Z'

        // Run mutation.
        const mu = new dgraph.Mutation();
        const assigned = await txn.mutate(mu);

        // Commit transaction.
        await txn.commit();

        console.log(`Created person named "somename" with uid = ${assigned.getUidsMap().get("somename")}\n`);

        console.log("All created nodes (map from blank node names to uids):");
        assigned.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
    } finally {
        // Clean up. Calling this after txn.commit() is a no-op
        // and hence safe.
        await txn.discard();

  async function main() {
  const dgraphClientStub = newClientStub();
  const dgraphClient = newClient(dgraphClientStub);

  await createData(dgraphClient);

  // Close the client stub.

main().then(() => {
}).catch((e) => {
  console.log("ERROR: ", e);

jpstrikesback commented :

Interesting! Are you using 1.1? I’m on 1.0.16

On Sat, Jul 13, 2019 at 5:15 PM Michel Conrado

Closed #59

You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub,
or mute the thread

MichelDiz commented :

"dgraph-js": "^1.3.0-rc1"

I’m using Dgraph from Master.

Dgraph version   : v1.0.12-rc3-571-ge4a07ad0
Commit SHA-1     : e4a07ad0
Commit timestamp : 2019-07-04 23:27:17 +0530
Branch           : master
Go version       : go1.12.6

MichelDiz commented :

I’ve just tested on v1.0.16 and is working.

Dgraph version   : v1.0.16
Commit SHA-1     : 0590ee95
Commit timestamp : 2019-07-11 11:52:54 -0700
Branch           : HEAD
Go version       : go1.12.5

jpstrikesback commented :

Oh wow! I owe you a beer! It turns out that a query that happens after the mutation but in the same transaction is where the issue was! I tested with your code and of course it worked…The blank node was making its way into the query: func(uid(_:somename))... and it was choking there. Ugh :confused:

Thanks for all your effort looking into this, super appreciated!!!