How do I check the type of a node in cypher?

Viewed 7244

I have a graph with three node types: NodeX, NodeY, and NodeZ

I have the this cypher query:

MATCH (x:NodeX)-[*]->(d)  
WHERE x.Name = 'pqr'  
RETURN x,d;

Here (d) may could be either NodeY or NodeZ. I'm looking to handle different nodetypes separately. Something like:

MATCH (x:NodeX)-[*]->(d)  
WHERE x.Name = 'pqr'  
WITH d
CASE WHEN typeof(d)=NodeY THEN {MATCH (y:NodeY)-[*]-(z:NodeZ)}
     WHEN typeof(d)=NodeZ THEN {MATCH (z:NodeZ)-[*]-(y:NodeY)}
RETURN y,z

y and z correspond to d. Is this possible to do so?

1 Answers
Related