2121import graphql .ExecutionInput ;
2222import graphql .GraphQLContext ;
2323import graphql .TrivialDataFetcher ;
24+ import graphql .execution .DataFetcherResult ;
2425import graphql .schema .DataFetcher ;
2526import graphql .schema .DataFetchingEnvironment ;
2627import graphql .schema .FieldCoordinates ;
3940import reactor .core .publisher .Mono ;
4041
4142import org .springframework .graphql .ExecutionGraphQlRequest ;
43+ import org .springframework .lang .Nullable ;
4244import org .springframework .util .Assert ;
4345
4446/**
@@ -74,7 +76,6 @@ private ContextDataFetcherDecorator(
7476 }
7577
7678
77- @ SuppressWarnings ("ReactiveStreamsUnusedPublisher" )
7879 @ Override
7980 public Object get (DataFetchingEnvironment env ) throws Exception {
8081
@@ -83,10 +84,33 @@ public Object get(DataFetchingEnvironment env) throws Exception {
8384 ContextSnapshot snapshot = (env .getLocalContext () instanceof GraphQLContext localContext ) ?
8485 snapshotFactory .captureFrom (graphQlContext , localContext ) :
8586 snapshotFactory .captureFrom (graphQlContext );
87+
8688 Mono <Void > cancelledRequest = graphQlContext .get (ExecutionGraphQlRequest .CANCEL_PUBLISHER_CONTEXT_KEY );
8789
8890 Object value = snapshot .wrap (() -> this .delegate .get (env )).call ();
8991
92+ if (value instanceof DataFetcherResult <?> dataFetcherResult ) {
93+ Object adapted = updateValue (dataFetcherResult .getData (), snapshot , cancelledRequest );
94+ value = DataFetcherResult .newResult ()
95+ .data (adapted )
96+ .errors (dataFetcherResult .getErrors ())
97+ .localContext (dataFetcherResult .getLocalContext ()).build ();
98+ }
99+ else {
100+ value = updateValue (value , snapshot , cancelledRequest );
101+ }
102+
103+ return value ;
104+ }
105+
106+ @ SuppressWarnings ("ReactiveStreamsUnusedPublisher" )
107+ private @ Nullable Object updateValue (
108+ @ Nullable Object value , ContextSnapshot snapshot , @ Nullable Mono <Void > cancelledRequest ) {
109+
110+ if (value == null ) {
111+ return null ;
112+ }
113+
90114 if (this .subscription ) {
91115 Flux <?> subscriptionResult = ReactiveAdapterRegistryHelper .toSubscriptionFlux (value )
92116 .onErrorResume ((exception ) -> {
0 commit comments