IF...ELSE with Cypher Neo4J

APOC Procedures just updated with support for conditional cypher execution. You'll need version 3.1.3.7 or greater (if using Neo4j 3.1.x), or version 3.2.0.3 or greater (if using Neo4j 3.2.x).

Here's an example of some of the cases you mentioned, using the new procedures:

CALL apoc.when($refs.client IS NOT NULL, 
 "MATCH (cl:client {uuid: refs.client}) RETURN cl", '', {refs:$refs}) YIELD value
WITH value.cl as cl  // which might be null...
...

...
CALL apoc.do.when(cl IS NOT NULL, 
 "DELETE tcr 
  MERGE (t)-[:references]->(cl)", '', {tcr:tcr, t:t, cl:cl}) YIELD value
...

...
RETURN {
  client: cl {.uuid}, ...
}

In your return, map projection is enough to meet your needs, you'll get an object with the uuid if cl exists, or a null for client if not.

Tags:

Neo4J

Cypher