I'm attempting to MATCH on a specific path depending on the property of an initial node.
E.g. I have a node, n, that has a property called nodeType. If node type is A then use the first MATCH, if node type is B then use the second MATCH.
I've attempted this using FOREACH. So when the case that nodeType is A, then return the node and it's relationships to other nodes. If the return type is B, then return its relationship to other nodes. In this case, it can only be one or the other, so only one will return a result. However, and this may be syntactic errors on my part, but where I'm asking it to execute a MATCH query, I cannot define the variables within the FOREACH.
Any help would be great.
MATCH (n: testNode)
WITH n
FOREACH(_ IN CASE WHEN n.nodeType == "A" THEN [MATCH (n)-[r]-(n2: testNode)] ELSE [] END | WITH n, r, n2)
FOREACH(_ IN CASE WHEN n.nodeType == "B" THEN [MATCH (n)--(n0)-[r]-(n2: testNode)] ELSE [] END | WITH n, r, n2)
WITH n, r, n2
RETURN n, COLLECT(r), COLLECT(n2)
Note: This is not the actual semantics of my MATCH queries. I have made them different just to show that they will do different things, but return the same types of nodes and relationships.