Upgrading to AnonymousTraversalSource ( Gremlin 3.3.5+ Node.js)

不羁岁月 提交于 2020-07-09 03:15:27

问题


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:


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...



来源:https://stackoverflow.com/questions/62624133/upgrading-to-anonymoustraversalsource-gremlin-3-3-5-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!