Search code examples
gremlinamazon-neptunegremlinnet

Getting request data with Gremlin.Net


I'm working with Gremlin.Net & Neptune and once a while some of the requests fail without much information in the error message (InternalFailureException).
I want to try and send the request through curl to the server's "/gremlin/explain" URL to get more information.
Since I build the request with the GraphTraversal class (and it is very long), I'm looking for a way to get the equivalent gremlin commands as the request which was sent.
Is there any easy way to get it?
Are there any other ways to understand why Neptune failed the request?


Solution

  • I assume you would like to get a String representation of your query so that you can POST it to the /gremlin/explain API. With Java and Javascript it's possible to do such a thing fairly directly with TinkerPop's Translator functions described here. Of course, for .NET and Python such things don't exist yet.

    Since your situation sounds like you just need a one-off solution to do some analysis with "explain" you could get the GraphSON representation of the bytecode in .NET, use Gremlin Console's :bytecode command to convert it to a String representation.

    So, first get the Bytecode object as GraphSON:

    var bytecode = g.V().Out("knows").Bytecode;
    var writer = new GraphSON3Writer();
    var graphSON = writer.WriteObject(bytecode)
    

    Copy/paste that "graphSON" string into Gremlin Console:

    gremlin> g = TinkerGraph.open().traversal()
    ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
    gremlin> :bytecode translate g {"@type":"g:Bytecode","@value":{"step":[["V"],["out","knows"]]}}
    ==>g.V().out("knows")
    

    Note that I use a TinkerGraph there just as a host to reconstruct the traversal.