Is there a way to create an intermediate virtual graph within a query and then query that graph further? Using apoc.create.vRelationship it is possible to create a new relationship with label "TEMP" and to return it. But I want to query paths using "TEMP", and that does not seem possible.
For instance, this should work:
MATCH (from:User)-[:SENT]->(p:Payment)-[:RECEIVED]->(to:Business), ... // matching other nodes related to p with critical data
RETURN from, to, apoc.create.vRelationship(from,'PAID',{... <various critical data>}) as rel;
But this won't work:
MATCH (root{id:$rootId}), (from:User)-[:SENT]->(p:Payment)-[:RECEIVED]->(to:Business), ... // matching other nodes related to p with critical data
WITH from, to, apoc.create.vRelationship(from,'PAID',{... <various critical data>}) as rel;
MATCH path = (root) -[:PAID*]-(to)
...
Virtual entities are just entities that are created and returned in query results. They are not persisted, so you can't query on them. Their purpose is more towards improving visualization of data, by allowing you to return just the information that is relevant for your use case. Two examples would be if you want to return only a subset of a nodes properties or you want to return a path that between two nodes and hide the fact that they are connected through multiple hops.
I did figure out that virtual relationships and/or entities will not allow for an intermediate graph. The question I'm asking is, what will?
The problem is that I want to:
identify related nodes and some vital data through what you call "multiple hops", and
return a JSON representing a tree of them. I know, for any group of nodes, which one is the root node, and I know that they form a simple tree. I can use code on the server to post-process the query result and derive the tree. But it would be so nice if I could derive the tree directly in the query. The only way I've seen to return a tree is using apoc.create.vRelationship. But that function cannot be called with virtual relationships.