Skip to content

Can't set transaction isolation level with withPgClientTransaction?ย #2630

@the-sun-will-rise-tomorrow

Description

Summary

In my plugin implementing a mutation, I tried doing:

  // ...

  plans: {
    Mutation: {
      submit(_, fieldArgs) {
        const $input = fieldArgs.getRaw("input");
        const executor =
          build.input.pgRegistry.pgResources["versions"].executor;

        const $result = withPgClientTransaction(
          executor,
          $input,
          async (pgClient, input) => {
            await pgClient.query({
              text: "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;",
            });

            // ...

However, this seems to throw an error: SET TRANSACTION ISOLATION LEVEL must be called before any query.

What query could have been called if I'm running SET TRANSACTION as the very first thing inside the withPgClientTransaction callback?

The GraphQL query contains calls to other mutations before this one. Could that have something to do with this?

Could there perhaps be another transaction active when withPgClientTransaction is called? Is there a top-level transaction for all mutations done by one GraphQL call? (If so, what is the point of withPgClientTransaction if everything happens in a transaction anyway?)

Also, do queries run in a transaction? Or, more specifically: which of the "phenomena" - as described on https://www.postgresql.org/docs/current/transaction-iso.html - are possible within a single GraphQL query?

Additional context

PostGraphile 5.0.0-beta.40 with PostgreSQL 16.4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    ๐ŸŒณ Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions