有一个新版本出来了,但是文档有点缺少一个工作示例。
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] }}
关于javascript - 工作 gremlin javascript 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49917571/