首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >工作gremlin javascript示例

工作gremlin javascript示例
EN

Stack Overflow用户
提问于 2018-04-19 09:32:08
回答 2查看 5.3K关注 0票数 2

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

集线器票:https://github.com/jbmusso/gremlin-javascript/issues/109

我一直想找个例子来证明这一点。任何帮助都值得赞赏:

gremlin-server: 3.3.2 with config gremlin-server-现代派

npm gremlin lib: 3.3.2

代码语言:javascript
复制
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)

当前产出:

代码语言:javascript
复制
[]
{ value: null, done: true }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-19 14:59:16

更新

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

工作实例:

代码语言:javascript
复制
const gremlin = require('gremlin');
const Graph = gremlin.structure.Graph;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

获取遍历源(g):

代码语言:javascript
复制
const graph = new Graph();
const connection = new DriverRemoteConnection('ws://localhost:8182/gremlin');
const g = graph.traversal().withRemote(connection);

一旦有了遍历源(g),就可以在应用程序中重用它来创建遍历,例如:

代码语言:javascript
复制
// 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:https://issues.apache.org/jira/browse/TINKERPOP-1943中提交了一张支持JavaScript的罚单

同时,作为一种解决办法,您可以将GraphSON2序列化器添加到服务器,方法是在yaml中添加下面一行,在serializers下面

代码语言:javascript
复制
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }}
票数 7
EN

Stack Overflow用户

发布于 2019-02-28 18:49:41

关于未定义问题的read属性“reader”。我又回到了gremlin@3.3.4版本,它运行得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49917571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档