Skip to content

Fix dropping of extensions in ContextDataFetcherDecorator #1199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ public Object get(DataFetchingEnvironment env) throws Exception {
Object value = snapshot.wrap(() -> this.delegate.get(env)).call();

if (value instanceof DataFetcherResult<?> dataFetcherResult) {
Object adapted = updateValue(dataFetcherResult.getData(), snapshot, graphQlContext);
value = DataFetcherResult.newResult()
.data(adapted)
.errors(dataFetcherResult.getErrors())
.localContext(dataFetcherResult.getLocalContext()).build();
value = dataFetcherResult.map(data -> updateValue(data, snapshot, graphQlContext));
}
else {
value = updateValue(value, snapshot, graphQlContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -366,4 +367,20 @@ void cancelFluxDataFetcherSubscriptionWhenRequestCancelled() throws Exception {
assertThat(dataFetcherCancelled).isTrue();
}

@Test
public void testExtensionsAreRetained() throws Exception {
GraphQL graphQl = GraphQlSetup.schemaContent(SCHEMA_CONTENT)
.queryFetcher("greeting", (env) ->
DataFetcherResult.newResult().data("Hello")
.extensions(Map.of("foo", "bar")).build())
.toGraphQl();

ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
ExecutionResult executionResult = graphQl.executeAsync(input).get();

String greeting = ResponseHelper.forResult(executionResult).toEntity("greeting", String.class);
assertThat(greeting).isEqualTo("Hello");

assertThat(executionResult.getExtensions()).containsEntry("foo", "bar");
}
}