TypeError: Cannot read property "serializeBinary" of undefined

Moved from GitHub dgraph-js/83

Posted by scroobius-pip:

versions:
dgraph-js: 2.0.1
grpc: 1.24.0
dgraph: 1.1.0

Coded using the 1.X.Y dgraph-js library with dgraph 1.0.1 , then i update the library and database to the latest versions and get the following error:
“TypeError: Cannot read property ‘serializeBinary’ of undefined”

here’s the offending code that worked perfectly on previous version but not this latest version:


import dgraph = require('dgraph-js')
import { data, schema } from './seed'

export default async (client: dgraph.DgraphClient) => {
    try {
        // set schema
        const op = new dgraph.Operation()
        op.setSchema(schema)
        await client.alter(op)

        // set mock data
        const transaction = client.newTxn()
        try {

            const mutation = new dgraph.Mutation()

            mutation.setSetJson(data)
            await transaction.mutate(mutation)
            await transaction.commit()

        } finally {
            transaction.discard()
        }

    } catch (error) {
        console.error(error)
        throw new Error(error)
    }
}

here’s how i’m initializing the client:

const initDgraphClient = (address: string) => {
  try {
    const clientStub = new dgraph.DgraphClientStub(address,
      grpc.credentials.createInsecure())
    const client = new dgraph.DgraphClient(clientStub)
    client.setDebugMode(true)
    return client
  } catch (error) {
    console.error(error)
    throw error
  }
}

prashant-shahi commented :

Thanks, @scroobius-pip for raising this issue. It happens when you fail to create a dgraphClient, usually because of invalid gRPC address or invalid ACL login credentials.

This issue has been resolved with this PR #77. ~We will be releasing the v2.0.2 soon.~

We have released v2.0.2.