spring-projects / spring-projects/spring-graphql
Spring @Transactional support
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 336
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Spring GraphQL datafetchers and controllers with @Transactional, including the custom instrumentation and ExecutionStrategy mentioned in the issue. Reproduce the query and mutation behavior after removing the instrumentation, including the Propagation.MANDATORY failure. Done means establishing whether Spring GraphQL supports a shared transaction approach or documenting the supported alternative.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100