Getting error when running doRequest

Moved from GitHub dgraph-js/72

Posted by paulrostorp:

Version 2.0.1:
Hi I am getting the following error when running any code from the readme…


(node:58011) UnhandledPromiseRejectionWarning: TypeError: jspb.Message.getBooleanFieldWithDefault is not a function
    at Function.proto.api.Request.toObject (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/generated/api_pb.js:368:28)
    at proto.api.Request.toObject (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/generated/api_pb.js:350:28)
    at Object.stringifyMessage (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/util.js:52:31)
    at Txn.<anonymous> (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/txn.js:132:64)
    at step (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/txn.js:43:23)
    at Object.next (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/txn.js:24:53)
    at /Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/txn.js:18:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/txn.js:14:12)
    at Txn.doRequest (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/txn.js:112:16)

any suggestions ?

prashant-shahi commented :

@paulrostorp May I know which Dgraph version are you running?

paulrostorp commented :

1.1.0
Checked in the logs of each container, all showing v1.1.0, and running without problems. Running new upserts from ratel dashboard works as well.
Getting this error in the js client when doing anything more than initializing the client…
Also tried running with play.dgraph.io as the db, but same error occurs.

prashant-shahi commented :

That shouldn’t be the case.

It would be really helpful if you could share the docker-compose file (if any) and the minimum code snippet that causes the error?

paulrostorp commented :

My docker-compose:

version: "3.2"
services:
  zero:
    image: dgraph/dgraph:latest
    volumes:
      - /data:/dgraph
    ports:
      - 5080:5080
      - 6080:6080
    restart: always
    command: dgraph zero --my=zero:5080
  server:
    image: dgraph/dgraph:latest
    volumes:
      - /data:/dgraph
    ports:
      - 8080:8080
      - 9080:9080
    restart: always
    command: dgraph alpha --my=server:7080 --lru_mb=4100 --zero=zero:5080
  ratel:
    image: dgraph/dgraph:latest
    ports:
      - 8000:8000
    command: dgraph-ratel
    restart: always

attempted code:

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

const clientStub = new dgraph.DgraphClientStub(
    process.env.DGRAPH_HOST + ":9080",
    grpc.credentials.createInsecure(),
  );
const dgraphClient = new dgraph.DgraphClient(clientStub);
dgraphClient.setDebugMode(true);
console.log('Dgraph host: ', process.env.DGRAPH_HOST);

main = async () => {
    const query = `query all($a: string) {
        all(func: eq(name, $a))
        {
          name
        }
      }`;
      const vars = { $a: "Alice" };
      const res = await dgraphClient.newTxn().queryWithVars(query, vars);
      const ppl = res.getJson();
      
      // Print results.
      console.log(`Number of people named "Alice": ${ppl.all.length}`);
}
main();

But any code from the readme or examples triggers the same error. I have performed a “drop all” on my db as well.

prashant-shahi commented :

There doesn’t seem to a problem running the following code snippet.

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

const clientStub = new dgraph.DgraphClientStub(
    "localhost:9080",
    grpc.credentials.createInsecure(),
  );
const dgraphClient = new dgraph.DgraphClient(clientStub);
dgraphClient.setDebugMode(true);
console.log('Dgraph host: ', process.env.DGRAPH_HOST);

async function setSchema() {
    const schema = `
        name: string @index(exact) .
        age: int @index(int) .
        friend: [uid] @reverse .
    `;
    const op = new dgraph.Operation();
    op.setSchema(schema);
    await dgraphClient.alter(op);
}

async function createData() {
    const txn = dgraphClient.newTxn();
    try {
        const p = {
            name: "Alice",
            age: 26,
            friend: [
                {
                    name: "Bob",
                    age: 24,
                },
                {
                    name: "Charlie",
                    age: 29,
                }
            ]
        };

        const mu = new dgraph.Mutation();
        mu.setSetJson(p);

        const req = new dgraph.Request();
        req.addMutations(mu);
        req.setCommitNow(true);
        const response = await txn.doRequest(req);

        console.log(`Created person named "Alice" with uid = ${response.getUidsMap().get("alice")}\n`);
        console.log("All created nodes (map from blank node names to uids):");
        response.getUidsMap().forEach((uid, key) => console.log(`${key} => ${uid}`));
        console.log();
    } finally {
        await txn.discard();
    }
}

main = async () => {
    await setSchema();
    await createData();
    const query = `query all($a: string) {
        all(func: eq(name, $a))
        {
          name
        }
      }`;
      const vars = { $a: "Alice" };
      const res = await dgraphClient.newTxn().queryWithVars(query, vars);
      const ppl = res.getJson();
      
      // Print results.
      console.log(`Number of people named "Alice": ${ppl.all.length}`);
}
main();

prashant-shahi commented :

can you delete any previously existing data (volumes)?
Also, make sure to pull the latest version from docker-hub - preferably use dgraph/dgraph:v1.1.0.

paulrostorp commented :

I just uninstall and reinstalled dgraph-js with yarn, thinking that maybe v2.0.1 had been installed improperly and strangely this is now the error I get:

Do request:
{"startTs":0,"query":"query all($a: string) {\n        all(func: eq(name, $a))\n        {\n          name\n        }\n      }","varsMap":[["$a","Alice"]],"readOnly":false,"bestEffort":false,"mutationsList":[],"commitNow":false}
(node:88133) UnhandledPromiseRejectionWarning: TypeError: Incorrectly typed arguments to startBatch
    at _startBatchIfReady (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client_interceptors.js:752:10)
    at Object.final_requester.start (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client_interceptors.js:801:21)
    at InterceptingCall._callNext (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client_interceptors.js:421:43)
    at InterceptingCall.start (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client_interceptors.js:456:8)
    at next (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client_interceptors.js:453:22)
    at InterceptingCall._callNext (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client_interceptors.js:428:12)
    at InterceptingCall.start (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client_interceptors.js:456:8)
    at ServiceClient.Client.makeUnaryRequest (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client.js:585:21)
    at ServiceClient.method_func [as query] (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/grpc/src/client.js:1000:43)
    at /Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/util.js:46:15

And with your code example I get this error:

Alter request:
{"schema":"\n        name: string @index(exact) .\n        age: int @index(int) .\n        friend: [uid] @reverse .\n    ","dropAttr":"","dropAll":false,"dropOp":0,"dropValue":""}
(node:90442) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'serializeBinary' of undefined
    at Object.createPayload (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/types.js:65:105)
    at DgraphClient.<anonymous> (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/client.js:86:36)
    at step (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/client.js:32:23)
    at Object.throw (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/client.js:13:53)
    at rejected (/Users/paulrostorp/Documents/Apps/kickoff-project/kickoff-api/node_modules/dgraph-js/lib/client.js:5:65)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

By “deleting data volumes” you mean delete the “p”, “w” and “zw” folder in “/data” ? If so I had already done so when updating to v1.1.0

prashant-shahi commented :

I see. The Dgraph client is not able to be initialized properly.

First of all, let’s pull the latest image from docker-hub, and the make sure Dgraph cluster is up and running. Try running some mutation and queries from either curl/tour/ratel.

Then, let’s make sure DGRAPH_HOST env var is accessible.
If not, using process.env.DGRAPH_HOST+":9080" will be getting resolved to undefined:9080.

Do let me know if this doesn’t resolve the issue.

paulrostorp commented :

Reinstalling dgraph didn’t work but rm -rf node_modules && yarn install did… or maybe a combination of both…

paulrostorp commented :

Thank you for your help. Are there any steps you’d like me to take in order to better understand the root of the problem ? Personally I cannot make sense of the errors thrown

prashant-shahi commented :

Glad to know that issue is resolved.

I had raised an issue similar to this one yesterday #71.

Thanks, Paul! We will be working on improving the error messages.