工作 gremlin javascript 示例

Working gremlin javascript example

有一个新版本出来了,但是文档中缺少一个有效的例子。

Github 门票:https://github.com/jbmusso/gremlin-javascript/issues/109

我一直在努力让一个例子起作用。任何帮助表示赞赏:

gremlin-server: 3.3.2 配置 gremlin-server-modern.yaml
npm gremlin 库:3.3.2

import gremlin from 'gremlin';
import DriverRemoteConnection from 'gremlin/lib/driver/driver-remote-connection';
import { Graph } from 'gremlin/lib/structure/graph';
const graph = new Graph()
const g = graph.traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin', { mimeType: 'application/vnd.gremlin-v3.0+json' }));

const fetchById = async (id) => {
  const result = await g.V(id).toList()
  console.log(result);
}

const addUser = async (name) => {
  const newVertex = await g.addV().property('name','marko').property('name','marko a. rodriguez').next()
  console.log(newVertex)
}

addUser()
fetchById(0)

当前输出:

[]
{ value: null, done: true }

更新

Gremlin JavaScript 现在支持 GraphSON3 和最新的 Gremlin 服务器。

工作示例:

const gremlin = require('gremlin');
const Graph = gremlin.structure.Graph;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

获取遍历源(g):

const graph = new Graph();
const connection = new DriverRemoteConnection('ws://localhost:8182/gremlin');
const g = graph.traversal().withRemote(connection);

获得遍历源 (g) 后,在您的应用程序中重复使用它来创建遍历,例如:

// Get the friends' names
const friends = await g.V().has("name","Matt")
                       .out("knows").values("name").toList();

查看文档的更多信息:https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript

原始答案

Gremlin JavaScript 不支持 GraphSON3 序列化,这是 TinkerPop 3.3+ 中的默认设置。这会导致您的响应无法正确解析。

我已经在 JavaScript GLV 中提交了支持 GraphSON3 的票证:https://issues.apache.org/jira/browse/TINKERPOP-1943

与此同时,作为一种解决方法,您可以通过将以下行添加到您的 yaml serializers:

下方来将 GraphSON2 序列化程序添加到服务器
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }}

关于读取属性'reader'未定义的问题。我退回到版本 gremlin@3.3.4 并且它工作正常。