2

I'm looking for a single query that can create a GraphSON serialisation of a full TinkerGraph graph.

// setup

const gremlin = require('gremlin')

const connection = new gremlin.driver.DriverRemoteConnection('ws://localhost:8182/gremlin')

const g = (new gremlin.structure.Graph()).traversal().withRemote(connection)

I'm able to serialise vertices, edges and properties separately as GraphSON. The following statements create a GraphSON serialisation of all vertices only. Edges can be queried with E(), and properties with V().properties().

// placed within an async function

const writer = new gremlin.structure.io.GraphSONWriter()

const serialisedVertices = writer.write(await g.V().toList())

Is there a gremlin-javascript method that will serialise all vertices, edges and properties together (rather than separately as above) into a GraphSON string in a single step?

Additionally if a full graph can be serialised as a single GraphSON string, is there also a matching invokation that will re-hydrate a graph instance from the GraphSON string?

sen
  • 23
  • 3
  • Do you have access to the server? Which graph server are you using? – Kfir Dadosh Aug 31 '19 at 17:58
  • Thanks for the reply - I'm using gremlin server with TinkerGraph, running on a virtual machine accessible via the localhost connection string above. I've edited the question for clarity – sen Aug 31 '19 at 20:14

1 Answers1

1

Starting gremlin 3.4.x you can use the io step:

g.io("graph.json").read().iterate()
g.io("graph.json").write().iterate()

These commands read/write the complete graph data in graphson format, which is a json file. There are more supported formats as written in the tinkerpop documentation

If you are running gremlin 3.3.x, you can use the following command:

graph.io(graphson()).writeGraph("graph.json");

Note that the file is stored on the gremlin server current working directory.

Kfir Dadosh
  • 1,411
  • 9
  • 9
  • Brilliant thanks - sadly it looks like the `io` property is not found in gremlin-javascript 3.4.3 (http://tinkerpop.apache.org/jsdocs/3.4.3/GraphTraversal.html, also confirmed from logging the objects) so serialising a full graph may not be possible unless there's a more suitable argument to pass to the write() method – sen Sep 01 '19 at 16:09
  • Since it must be the first step in the traversal, it is implemented in GraphTraversalSource. Take a look here: http://tinkerpop.apache.org/jsdocs/3.4.3/GraphTraversalSource.html – Kfir Dadosh Sep 01 '19 at 16:56