Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setSetJson() does not support named blank nodes #59

Closed
jpstrikesback opened this issue Jul 13, 2019 · 7 comments
Closed

setSetJson() does not support named blank nodes #59

jpstrikesback opened this issue Jul 13, 2019 · 7 comments

Comments

@jpstrikesback
Copy link

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
Copy link
Contributor

MichelDiz commented Jul 13, 2019

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
Copy link
Author

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();
    mutation.setSetJson(node);
    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
Copy link
Contributor

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();
        mu.setSetJson(p);
        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}`));
        console.log();
    } 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.
  dgraphClientStub.close();
}

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

@jpstrikesback
Copy link
Author

jpstrikesback commented Jul 13, 2019 via email

@MichelDiz
Copy link
Contributor

"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
Copy link
Contributor

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
Copy link
Author

jpstrikesback commented Jul 13, 2019

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 :/

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants