Skip to content

Spring @Transactional support #448

Open
@koenpunt

Description

@koenpunt

When we first started with spring we used JPA and made heavy use of its relational support. This caused some issues with spring-graphql because sometimes lazy associations were accessed in a field resolver, causing an error that said something like "there isn't an active transaction".
We worked around this by writing a custom instrumentation to start a transaction for every query and mutation.

Now that's we removed all associations (in preparation of migrating to R2DBC), we no longer need this transaction by default. But removing this instrumentation somehow causes a significant increase in queries.

Adding @Transactional to graphql controllers doesn't seem to make a difference. Also adding @Transactional to a parent controller, and @Transactional(propagation = Propagation.MANDATORY) to controller of an underlying type controller, causes the execution to fail with:

org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'

This seems odd to me, because I would expect a transaction to exist there because of the transaction started in the parent controller. After some discussion with a teammate I've realized this isn't odd, because both controllers are invoked separately by the datafetchers, and thus not sharing the transaction. It still would be very welcome to have a solution for this.

Is there any support for transactions in Spring Graphql? Or is using a custom instrumentation (or ExecutionStrategy) the only way out for this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions