Graph state when executing triggers

When calling a query module from a trigger statement, what I expected to get within a function was a state of the graph before the query changes occurred. However, this is not the case and made changes are already visible in the graph state. I’ll write a dummy example of such behavior:

CREATE TRIGGER my_trigger ON CREATE
BEFORE COMMIT EXECUTE
CALL my_module.function(createdVertices, createdEdges) YIELD node, property
SET node.property = property;

Function my_module.function should execute after following statement:

MATCH (n {id: 19}), (m {id: 10}), (u {id: 14})
CREATE (n)-[new_edge_1:RELATION]->(m), (n)-[new_edge_2:RELATION]->(u)

In my_module.function, we’ll see a graph state with just created new_edge_1 and new_edge_2. If our calculation depends on having incremental changes, where we need the state of graph before any changes occur, is there a way to do it inside Memgraph with triggers?

1 Like

Unfortunately, there is no way to do that with the triggers.
During a single transaction, the changes of each query are visible in the next query. Triggers basically execute their statements as a query that is part of that transaction (if the BEFORE COMMIT is used).

You could probably use the changed values and ignore edges that are created in that transaction?

1 Like

Yeah, after this realization, I intended to do exactly what you mentioned. Tnx

2 Likes