Aborting a transation from Cypher

Is it possible to force a transaction to fail within the Cypher query itself.

The use case is a write transaction that makes some changes to the graph and then at the end of the query uses apoc.nodes.cycles to check to see if any cycles were introduced. If so, then I'd like to fail the transaction.

Michael-

I don't believe so in Neo4j Browser, as it uses implicit transactions, which are auto-close. I don't know of a command to rollback the changes.

The cypher-shell uses explicit transactions, where you have to manage the transactions. You could either commit or rollback the changes based on your outcome.

https://neo4j.com/docs/cypher-manual/current/introduction/transactions/

You can abort a cypher statement by using apoc.util.validate within the statement.

apoc.util.validate - APOC Documentation (neo4j.com)

You can try MERGE statement with null value.

MERGE (n:StopExecution {id: $not_a_valid_param})

This will throw an exception and aborts the transaction as you cannot do a MERGE with null values.