Search code examples
gographgremlingraph-traversal

Embedded gremlin server via gremlin-go library in golang


I'm new to Golang and need to find an analog to org.apache.tinkerpop.gremlin.tinkergraph.structure. TinkerGraph to use gremlin methods for traversing embedded graphs without connection to graph database.

I've found gremlin-go (github.com/apache/tinkerpop/gremlin-go/v3/driver), that suites my needs, except the fact that it needs connection to gremlin server. Is there any way to initialize GraphTraversalSource without connection to server, like it is done in Java version via this code?

Graph graph = TinkerGraph.open();
GraphTraversalSource g = traversal().withEmbedded(graph);

I've tried the following:

package main

import (
   "fmt"
   gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

func main() {
   graph := gremlingo.Graph{}
   gts := gremlingo.NewGraphTraversalSource(&graph, nil, gremlingo.ReadOnlyStrategy())
   prop := &gremlingo.GremlinType{"java.lang.Object"}
   gts.AddV("type_test").Property("data", prop).Iterate()
   cnt, _ := gts.V().Count().ToList()
   val, _ := cnt[0].GetInt32()
   fmt.Println(val)
}

But get out of bounds exception, meaning, that no vertices had been added. Is there any way to create graph locally and then traverse it?


Solution

  • No - this is not possible. gremlin-go is not an implementation of the Gremlin query processing engine nor does it expose interfaces as Java does to even implement a graph database. Like all the non-JVM based Gremlin implementations, it delegates that processing to Gremlin Server which has those capabilties.