graphile / graphile/crystal

Can't set transaction isolation level with `withPgClientTransaction`?

Open
#2,630 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12.9k
Forks
625
Avg merge
5h 23m
Merged PRs (30d)
24

Description

### Summary

In my plugin implementing a mutation, I tried doing:

```typescript
// ...

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.