#When does a mutation commit?

2 messages · Page 1 of 1 (latest)

broken cave
#

I assume this is a silly question, but I'm just wanting to check that if I call a mutation from an action that the mutation will have succeeded or failed when the mutation call returns?

I'm basically wanting to do:

actionA:
    runMutation(lockRecord);
    try {
        // do stuff while I'm holding the lock
    } finally {
        runMutation(releaseRecord);
    }

Just asking because queries and mutations are deterministic, and the talk in the docs about it being safe to retry them.

rapid cape
#

The mutation has committed by the time await ctx.runMutation in an action returns. So you can use mutations to take locks.

Note that actions can fail at any point, so it's not guaranteed that the finallyMutation will run. If you want to make sure that the lock gets released, you will need a backup method to release locks that have been held for too long.