Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Feb 12, 2025
1 parent ba05a3f commit b977bef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import graphql.GraphQL;
import graphql.GraphQLContext;
import graphql.GraphQLError;
import graphql.GraphQLException;
import graphql.execution.ExecutionIdProvider;
import graphql.execution.instrumentation.dataloader.EmptyDataLoaderRegistryInstance;
import io.micrometer.context.ContextSnapshotFactory;
Expand Down Expand Up @@ -105,12 +104,8 @@ public final Mono<ExecutionGraphQlResponse> execute(ExecutionGraphQlRequest requ
ExecutionInput executionInputToUse = registerDataLoaders(executionInput);

return Mono.fromFuture(this.graphQlSource.graphQl().executeAsync(executionInputToUse))
.onErrorResume(GraphQLException.class, (exception) -> {
if (exception instanceof GraphQLError graphQLError) {
return Mono.just(ExecutionResult.newExecutionResult().addError(graphQLError).build());
}
return Mono.error(exception);
})
.onErrorResume((ex) -> ex instanceof GraphQLError, (ex) ->
Mono.just(ExecutionResult.newExecutionResult().addError((GraphQLError) ex).build()))
.map((result) -> new DefaultExecutionGraphQlResponse(executionInputToUse, result));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ void customDataLoaderRegistry() {

@Test
void shouldHandleGraphQlErrors() {
GraphQlSource graphQlSource = GraphQlSetup.schemaContent("type Query { greeting: String }")
ExecutionGraphQlResponse response = GraphQlSetup.schemaContent("type Query { greeting: String }")
.queryFetcher("greeting", (env) -> "hi")
.toGraphQlSource();
DefaultExecutionGraphQlService graphQlService = new DefaultExecutionGraphQlService(graphQlSource);
.toGraphQlService()
.execute(new DefaultExecutionGraphQlRequest("{ greeting }", "unknown", null, null, "uniqueId", null))
.block();

ExecutionGraphQlRequest request = new DefaultExecutionGraphQlRequest("{ greeting }", "unknown",
null, null, "uniqueId", null);
ExecutionGraphQlResponse response = graphQlService.execute(request).block();
assertThat(response.getExecutionResult().getErrors()).singleElement()
.hasFieldOrPropertyWithValue("errorType", ErrorType.ValidationError);
}
Expand Down

0 comments on commit b977bef

Please sign in to comment.