-
Notifications
You must be signed in to change notification settings - Fork 47
Graph Aspects
Graph aspects are like Aspect Oriented Programming - but for graphs. They enable cross cutting graph mutations for a variety of reasons.
As an example, consider a domain that includes evidence for pairs of nodes (ie subject / object). The domain model look something like this:
where the association contains metadata about the fact that thing0
causes thing1
. This pattern would be very trivial to capture with Cypher:
MATCH path = (a)-[:causes]->(b),
(a)<-[:subject]-(metadata)-[:object]->(b)
RETURN path, metadata
In this case the path from a
to b
is of interest but the metadata is also useful to return. As paths from a
to b
become more complex, so do queries to get all of their evidence. Consider:
or
where the path between the start of the causation and the end of the causation is not direct and has a variable number of nodes in the path. In this case the Cypher needed to capture the extra metadata explodes and requires many OPTIONAL
clauses.
Graph aspects are designed to address just such concerns. Graph aspects simply implement an invoke
method that will receive an in memory TinkerGraph containing a single row of the Cypher result and mutate it as needed - keeping the initial Cypher query lean and focused. Aspects also have access to the underlying GraphDatabaseService
to traverse as needed.