admin管理员组文章数量:1400621
There is a new version out, but the documentation is somewhat lacking a working example.
Github Ticket:
I've been trying to get an example to work. Any help appreciated:
gremlin-server: 3.3.2 with config gremlin-server-modern.yaml
npm gremlin lib: 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)
Current Output:
[]
{ value: null, done: true }
There is a new version out, but the documentation is somewhat lacking a working example.
Github Ticket: https://github./jbmusso/gremlin-javascript/issues/109
I've been trying to get an example to work. Any help appreciated:
gremlin-server: 3.3.2 with config gremlin-server-modern.yaml
npm gremlin lib: 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)
Current Output:
[]
{ value: null, done: true }
Share
Improve this question
asked Apr 19, 2018 at 9:32
Mathias MaciossekMathias Maciossek
2454 silver badges12 bronze badges
2 Answers
Reset to default 7UPDATE
Gremlin JavaScript now supports GraphSON3 and the latest Gremlin Server.
Working example:
const gremlin = require('gremlin');
const Graph = gremlin.structure.Graph;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
Obtain a traversal source (g
):
const graph = new Graph();
const connection = new DriverRemoteConnection('ws://localhost:8182/gremlin');
const g = graph.traversal().withRemote(connection);
Once you have a traversal source (g
), reuse it across your application to create traversals, for example:
// Get the friends' names
const friends = await g.V().has("name","Matt")
.out("knows").values("name").toList();
See more information on the documentation: https://tinkerpop.apache/docs/current/reference/#gremlin-javascript
ORIGINAL ANSWER
Gremlin JavaScript doesn't support GraphSON3 serialization, which is the default in TinkerPop 3.3+. This causes your response to not be properly parsed.
I've filed a ticket to support GraphSON3 in the JavaScript GLV: https://issues.apache/jira/browse/TINKERPOP-1943
In the meantime, as a workaround, you can add GraphSON2 serializers to the server by adding the following line to your yaml, below serializers
:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }}
Regarding the read property 'reader' of undefined issue. I falled back to version [email protected] and it works fine.
本文标签: Working gremlin javascript exampleStack Overflow
版权声明:本文标题:Working gremlin javascript example - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744269717a2598123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论