Search code examples
javagremlinjanusgraph

Can I execute a Gremlin query against an embedded JanusGraph instance?


I'm aware of the native Java api for an embedded JanusGraph, but can I execute a Gremlin syntax String directly against the graph [in java]?

The reason is that I have existing Gremlin queries that currently execute against a standalone Gremlin server.

The queries are executed from a client side app, so it would be nice to save time.


Solution

  • Just to be clear, that "native API" enables the execution of Gremlin against it, but not as strings. You would simply use Gremlin Java:

    graph = // make your JanusGraph instance
    g = graph.traversal();
    List<Vertex> vertices = g.V().toList();
    

    But if you are literally asking if you can "execute a Gremlin syntax String directly against the graph" then the answer is "no". It's NOT as though you can do:

    graph = // make your JanusGraph instance
    List<Vertex> vertices = graph.eval("g.V()").toList();
    

    If you really needed to do this, I suppose you could utilize the GremlinGroovyScriptEngine to pass in JanusGraph as a binding and then eval a Gremlin string against that, but unless you need to process completely dynamic Gremlin traversals, I'm not sure I'd see a reason to do that.