Dgraph-js and auth-token problem - Error: Incorrect arguments passed

I have some problems with the latest changes to the client dgraph-js (v20.3.1) in combination with the grpc (v1.24.3) client.

When I launch dgraph I use the auth-token attribute:

docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph  dgraph/dgraph:latest dgraph zero
docker exec -it dgraph dgraph alpha --lru_mb 2048 --zero localhost:5080 --whitelist --auth_token "secret"

When I try to run the dgraph-js sample client, where I have updated the package.json to the latest versions.

------- package.json
  "name": "simple",
  "dependencies": {
    "dgraph-js": "^20.3.1",
    "grpc": "^1.24.3"

And when adding metadata to the alter operations with the auth-token as in this updated simple example file.

---- simple - index.js
const dgraph = require("dgraph-js");
const grpc = require("grpc");

let meta = new grpc.Metadata();
meta.add("auth-token", "secret");

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

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

// Drop All - discard all data, schema and start from a clean slate.
async function dropAll(dgraphClient) {
    const op = new dgraph.Operation();
    await dgraphClient.alter(op, meta);

// Drop All Data, but keep the schema.
async function dropData(dgraphClient) {
    const op = new dgraph.Operation();
    await dgraphClient.alter(op, meta);

// Set schema.
async function setSchema(dgraphClient) {
    const schema = `
        name: string @index(exact) .
        age: int .
        married: bool .
        loc: geo .
        dob: datetime .
        friend: [uid] @reverse .
    const op = new dgraph.Operation();
    await dgraphClient.alter(op, meta);

// Create data using JSON.
async function createData(dgraphClient) {
    // Create a new transaction.
    const txn = dgraphClient.newTxn();
    try {
        // Create data.
        const p = {
            uid: "_:alice",
            name: "Alice",
            age: 26,
            married: true,
            loc: {
                type: "Point",
                coordinates: [1.1, 2],
            dob: new Date(1980, 1, 1, 23, 0, 0, 0),
            friend: [
                    name: "Bob",
                    age: 24,
                    name: "Charlie",
                    age: 29,
            school: [
                    name: "Crown Public School",

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

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

        // Get uid of the outermost object (person named "Alice").
        // Response#getUidsMap() returns a map from blank node names to uids.
        // For a json mutation, blank node label is used for the name of the created nodes.
            `Created person named "Alice" with uid = ${response

        console.log("All created nodes (map from blank node names to uids):");
            .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();

// Query for data.
async function queryData(dgraphClient) {
    // Run query.
    const query = `query all($a: string) {
        all(func: eq(name, $a)) {
            friend {
            school {
    const vars = { $a: "Alice" };
    const res = await dgraphClient
        .newTxn({ readOnly: true })
        .queryWithVars(query, vars);
    const ppl = res.getJson();

    // Print results.
    console.log(`Number of people named "Alice": ${ppl.all.length}`);
    ppl.all.forEach((person) => console.log(person));

async function main() {
    const dgraphClientStub = newClientStub();
    const dgraphClient = newClient(dgraphClientStub);
    await dropAll(dgraphClient);
    await setSchema(dgraphClient);
    await createData(dgraphClient);
    await queryData(dgraphClient);
    await dropData(dgraphClient);
    await queryData(dgraphClient);
    await createData(dgraphClient);
    await queryData(dgraphClient);

    // Close the client stub.

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

When I try to run the simple example I get the following errors:

ERROR:  Error: Incorrect arguments passed
    at ServiceClientImpl.checkOptionalUnaryResponseArguments (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/@grpc/grpc-js/build/src/client.js:111:23)
    at ServiceClientImpl.makeUnaryRequest (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/@grpc/grpc-js/build/src/client.js:118:39)
    at ServiceClientImpl.alter (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/@grpc/grpc-js/build/src/make-client.js:93:19)
    at /Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/dgraph-js/lib/util.js:53:15
    at new Promise (<anonymous>)
    at Object.alter (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/dgraph-js/lib/util.js:52:16)
    at DgraphClientStub.alter (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/dgraph-js/lib/clientStub.js:95:33)
    at DgraphClient.<anonymous> (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/dgraph-js/lib/client.js:67:42)
    at step (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/dgraph-js/lib/client.js:33:23)
    at Object.next (/Users/erlendo/tmp/dgraph-js/examples/simple/node_modules/dgraph-js/lib/client.js:14:53)

If someone could provide some light to why this happens, and what I’m doing wrong, that would be most appreciated.


My bad…

I found that when I changed from:

var grpc = require('grpc')


var grpc = require('@grpc/grpc-js')

It works as expected.

Sorry for the trouble, and thanks for the help of providing appropriate formatting.


1 Like

Thanks @erlendoverby, we will update the README on dgraph-js. grpc package is on the way out and @grpc/grpc-js will be supported by the grpc devs.