spring-graphql icon indicating copy to clipboard operation
spring-graphql copied to clipboard

Using @Transactional for Subscriptions data fetcher

Open MathisPct opened this issue 1 month ago • 0 comments

Hello,

We were wondering whether it’s possible to define an execution strategy (or anything else) that would run the data fetchers for each new message in the subscription flux within a transaction, similar to the following code, which handles this for queries and mutations :

public class TransactionalAsyncExecutionStrategy extends AsyncExecutionStrategy {

    public TransactionalAsyncExecutionStrategy(
            final DataFetcherExceptionHandler handler
    ) {
        super(handler);
    }

    @Override
    @Transactional
    public CompletableFuture<ExecutionResult> execute(
            final ExecutionContext executionContext,
            final ExecutionStrategyParameters parameters
    ) throws NonNullableFieldWasNullException {
        return super.execute(executionContext, parameters);
    }
}

How can we cover this case ?

Thank you by advance

Another sources:

https://github.com/spring-projects/spring-graphql/issues/448#issuecomment-1825502735

MathisPct avatar Nov 17 '25 14:11 MathisPct