Skip to content

Commit 2ce7bfc

Browse files
committed
Merge branch '1.3.x'
2 parents ae40015 + d30429f commit 2ce7bfc

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

spring-graphql/src/main/java/org/springframework/graphql/execution/ContextDataFetcherDecorator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ public Object get(DataFetchingEnvironment env) throws Exception {
9292
Object value = snapshot.wrap(() -> this.delegate.get(env)).call();
9393

9494
if (value instanceof DataFetcherResult<?> dataFetcherResult) {
95-
Object adapted = updateValue(dataFetcherResult.getData(), snapshot, graphQlContext);
96-
value = DataFetcherResult.newResult()
97-
.data(adapted)
98-
.errors(dataFetcherResult.getErrors())
99-
.localContext(dataFetcherResult.getLocalContext()).build();
95+
value = dataFetcherResult.map((data) -> updateValue(data, snapshot, graphQlContext));
10096
}
10197
else {
10298
value = updateValue(value, snapshot, graphQlContext);

spring-graphql/src/test/java/org/springframework/graphql/execution/ContextDataFetcherDecoratorTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020
import java.util.Collections;
2121
import java.util.List;
22+
import java.util.Map;
2223
import java.util.concurrent.CompletableFuture;
2324
import java.util.concurrent.atomic.AtomicBoolean;
2425
import java.util.function.BiConsumer;
@@ -366,4 +367,20 @@ void cancelFluxDataFetcherSubscriptionWhenRequestCancelled() throws Exception {
366367
assertThat(dataFetcherCancelled).isTrue();
367368
}
368369

370+
@Test
371+
void testExtensionsAreRetained() throws Exception {
372+
GraphQL graphQl = GraphQlSetup.schemaContent(SCHEMA_CONTENT)
373+
.queryFetcher("greeting", (env) ->
374+
DataFetcherResult.newResult().data("Hello")
375+
.extensions(Map.of("foo", "bar")).build())
376+
.toGraphQl();
377+
378+
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
379+
ExecutionResult executionResult = graphQl.executeAsync(input).get();
380+
381+
String greeting = ResponseHelper.forResult(executionResult).toEntity("greeting", String.class);
382+
assertThat(greeting).isEqualTo("Hello");
383+
384+
assertThat(executionResult.getExtensions()).containsEntry("foo", "bar");
385+
}
369386
}

0 commit comments

Comments
 (0)