I'm trying to figure out if there's any way that I can access the data about what nodes/relationships have been modified in the current transaction so far, then run some application validation code based on that data, and then decide whether to commit or rollback the transaction. Is that possible?
I know that a before phase trigger has the information I need (via
assignedNodeProperties, etc.), but there seems to be no way to run application code between this trigger happening and the actual commit of the transaction. (I even tried throwing an exception in the trigger, thinking I could try to commit, put the data I want into the transaction metadata within the trigger, throw an exception in the trigger, then catch the exception in my application, update the transaction based on the metadata, and then try the commit [and trigger] again, but it seems that if the trigger throws an exception then the whole transaction is closed and one cannot try to commit again.)
I looked into a custom procedure, because something like
CALL my.procedures.getCurrentTransactionChanges() yield createdRelationships, ... would work perfectly, but from what I can tell, the information I need is only readily available via
ReadableTransactionState and to get that I'd need
KernelTransactionImplementation.txState(). I can see that this system procedure has a way of getting the
KernelTransactionImplementation, but from reading the procedure context docs it seems clear that this would be an unsupported/private API and subject to change at any time.
Is there a better way to get this information?
The use case is: I want to allow application code to use cypher to make arbitrary changes to the database, but then before committing those changes I want to validate properties (e.g. username must be lowercase, that sort of thing), enforce business logic like ensuring certain relationships are 1:1, etc. It's a TypeScript application so I want the validation to happen in application code for various reasons; I know I could write triggers to do limited validation in Cypher but it wouldn't be as effective. If this is a terrible idea for some reason, I'd also like to know.