【问题标题】:Working gremlin javascript example工作 gremlin javascript 示例
【发布时间】:2018-04-19 09:32:08
【问题描述】:

有一个新版本出来了,但是文档中缺少一个工作示例。

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 }

【问题讨论】:

    标签: javascript gremlin gremlin-server


    【解决方案1】:

    更新

    Gremlin JavaScript 现在支持 GraphSON3 和最新的 Gremlin Server。

    工作示例:

    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+ 中的默认设置。这会导致您的响应无法正确解析。

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

    同时,作为一种变通方法,您可以将 GraphSON2 序列化程序添加到服务器,方法是将以下行添加到您的 yaml 中,位于 serializers 下方:

    - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }}
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-03
        • 2020-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-05
        • 2012-08-14
        相关资源
        最近更新 更多