EmperorRXF/postgraphile-plugin-atomic-mutations

Is not Postgres function run on a transaction?

Closed this issue · 2 comments

Is not Postgres function run on a transaction?

Postgres does have a concept of transactions yes. I guess you're questioning why we need such a Plugin if Postgres has already atomicity built-in?

In Postgraphile v4, the default behavior when your client makes a single GQL request which contains more than one mutation (i.e. like this) is, each mutation there will run on it's own Postgres transaction. The outcome of each mutation will be isolated.

This might not be the preferred behavior for some clients. Maybe someone would want to consider the mutations enclosed within the GQL request to be treated in a single Postgres transaction.

This plugin attempts to address this particular issue by starting a Postgres SAVEPOINT before everything starts, and by either commiting everything if all mutations succeed or rollback everything if at least one mutation would fail.

@EmperorRXF Thanks for the quick and clear response, I did not thought about this earlier. As I understood this plugin is useful for automatically generated mutations, since if you write custom function it is not necessary since all mutations inside the function belong to an one transaction AFAIK.