简体   繁体   中英

How to apply a static has step on all the visited nodes/edges for a given traversal gremlin query

We are stamping user permission as a property (of SET cardinality) on each nodes and edges. Wondering what is best way to apply the has step on all the visited nodes/edges for a given traversal gremlin query.

like a very simple travarsal query: // Flights from London Heathrow (LHR) to airports in the USA

g.V().has('code','LHR').out('route').has('country','US').values('code')

add has('permission', 'team1') to all the visited vertices and edges while traversal using the above query.

There are two approaches you may consider.

  1. Write a custom TraversalStrategy
  2. Develop a Gremlin DSL

For a TraversalStrategy you would develop one similar to SubgraphStrategy or PartitionStrategy which would take your user permissions on construction and then automatically inject the necessary has() steps after out() / in() sorts of steps. The drawback here is that your TraversalStrategy must be written in a JVM language and if using Gremlin Server must be installed on the server. If you intend to configure this TraversalStrategy from the client-side in any way you would need to build custom serializers to make that possible.

For a DSL you would create new navigational steps for out() / in() sorts of steps and they would insert the appropriate combination of navigation step and has() step. The DSL approach is nice because you could write it in any programming language and it would work, but it doesn't allow server-side configuration and you must always ensure clients use the DSL when querying the graph.

We are stamping user permission as a property (of SET cardinality) on each nodes and edges.

As a final note, by "SET cardinality" I assume that you mean multi-properties . Edges don't allow for those so you would only be able to stamp such a property on vertices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM