Polishing
This commit is contained in:
@@ -26,7 +26,6 @@ import graphql.ExecutionResult;
|
||||
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;
|
||||
@@ -105,12 +104,8 @@ public class DefaultExecutionGraphQlService implements ExecutionGraphQlService {
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -67,14 +67,12 @@ public class DefaultExecutionGraphQlServiceTests {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user