Skip to content

Commit

Permalink
Merge branch '1.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Feb 12, 2025
2 parents 99594c4 + db78043 commit 803df55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ public ErrorClassification getErrorType() {
return graphql.ErrorType.valueOf(classification);
}
catch (IllegalArgumentException ex) {
return org.springframework.graphql.execution.ErrorType.valueOf(classification);
try {
return org.springframework.graphql.execution.ErrorType.valueOf(classification);
}
catch (IllegalArgumentException ex2) {
return ErrorClassification.errorClassification(classification);
}
}
}

Expand Down
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 803df55

Please sign in to comment.