Upgrading to AnonymousTraversalSource ( Gremlin 3.3.5+ Node.js)

Viewed 264

I'm writing code in Lamda Nodejs12.x

I wanted to update to the not-deprecated way of connecting

const gremlin = require('gremlin');
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const traversal = gremlin.process.AnonymousTraversalSource.traversal;

const clusterEndpoint = process.env.CLUSTER_ENDPOINT;
const port = process.env.CLUSTER_PORT;

const connectionStrArray = [];
connectionStrArray.push("wss://");
connectionStrArray.push(clusterEndpoint);
connectionStrArray.push(":");
connectionStrArray.push(port.toString());
connectionStrArray.push("/gremlin");

let joinedConnection = connectionStrArray.join("")
console.log(joinedConnection)
let dc = new DriverRemoteConnection(joinedConnection);

const g = traversal().withRemote(dc)

And then some await g.V().hasLabel or similar.

But all I get is: Cannot read property 'processor' of undefined

It worked fine the old way with Graph (3.3.4) https://github.com/apache/tinkerpop/blob/3.3.5/CHANGELOG.asciidoc#release-3-3-5

const graph = new Graph();
const g = graph.traversal().withRemote(dc);

What am I doing wrong? What have I missed?

UPDATE

Apparently I need to add travelsource?

{ traversalSource: 'g' }

I cannot find any documentation that added this and it is referenced only sparsly..

Update 2

For the lazy: Here is the code that I got working

const gremlin = require('gremlin');
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

const clusterEndpoint = process.env.CLUSTER_ENDPOINT;
const port = process.env.CLUSTER_PORT;

const connectionStrArray = [];
connectionStrArray.push("wss://");
connectionStrArray.push(clusterEndpoint);
connectionStrArray.push(":");
connectionStrArray.push(port.toString());
connectionStrArray.push("/gremlin");

const g = traversal().withRemote(new DriverRemoteConnection(connectionStrArray.join(""), { traversalSource: 'g' }));
1 Answers

The same error happened to me:

TypeError: Cannot read property 'processor' of undefined

traversalSource is not required, the specific solution is to pass an empty object to the second parameter of DriverRemoteConnection:

const g = traversal().withRemote(new DriverRemoteConnection(process.env.DATABASE_URL_LOCAL, {}));

So the problem seems to be an internal null check that is missing in the gremlin client.

When I updated the gremlin server this started to happen, I didn't change anything on the client, strange...

Related