3

Tinkerpop 2 used to support user-defined step through Gremlin.defineStep(..)

How can I achieve the same using Tinkerpop 3 ?

Is there any Gremlin API to create a custom step and combine a set of traversal steps ?

Any suggestion will be highly appreciated.

Thanks Kaniska

kaniska Mandal
  • 189
  • 1
  • 12

1 Answers1

5

Patterns for DSL development are not completely established for TinkerPop 3.x, so expect some changes in advice as time progresses. There is surrounding information on this on the gremlin-users mailing list.

If you are using Gremlin Server (or can incorporate Groovy into your project) I don't see a reason to not just do some groovy metaprogramming to get this to work. Using the standard Gremlin Server zip distribution edit the generate-modern.groovy file to include this line at the start:

GraphTraversal.metaClass.knows = { delegate.out('knows') }

then start the server with:

bin/gremlin-server.sh conf/gremlin-server-rest-modern.yaml

Then a simple curl:

$ curl "http://localhost:8182?gremlin=g.V(1).knows().values('name')"
{"requestId":"66c2c929-9cc2-491d-acb0-ae4d7eef6b00","status":{"message":"","code":200,"attributes":{}},"result":{"data":["vadas","josh"],"meta":{}}}

If you have a complex DSL you might not want all that logic trapped in a groovy script. Easy enough - just build a standard groovy project, construct a jar, include some form of static initializer to call your metaprogramming code and place it on Gremlin Server's path. then your init script just needs to call that static initializer and your DSL is loaded.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135