Configure exception resolver for `@GraphQlExceptionHandler` methods

To apply `@ControllerAdvice` exception handling to non-controller
DataFetcher implementations like QueryDslDataFetcher,
QueryByExampleDataFetcher, and others, this commit exposes the
DataFetcherExceptionResolver from AnnotatedControllerConfigurer as a
bean. The existing auto-configured for DataFetcherExceptionResolver
then picks this up and passes it into the builder used to create the
GraphQlSource.

Closes gh-34526
pull/34613/head
Andy Wilkinson 2 years ago
parent 45d36a5f42
commit eda299df90

@ -148,6 +148,12 @@ public class GraphQlAutoConfiguration {
return controllerConfigurer;
}
@Bean
DataFetcherExceptionResolver annotatedControllerConfigurerDataFetcherExceptionResolver(
AnnotatedControllerConfigurer annotatedControllerConfigurer) {
return annotatedControllerConfigurer.getExceptionResolver();
}
static class GraphQlResourcesRuntimeHints implements RuntimeHintsRegistrar {
@Override

@ -116,8 +116,10 @@ class GraphQlAutoConfigurationTests {
GraphQlSource graphQlSource = context.getBean(GraphQlSource.class);
GraphQL graphQL = graphQlSource.graphQl();
assertThat(graphQL.getQueryStrategy()).extracting("dataFetcherExceptionHandler")
.satisfies((exceptionHandler) -> assertThat(exceptionHandler.getClass().getName())
.endsWith("ExceptionResolversExceptionHandler"));
.satisfies((exceptionHandler) -> {
assertThat(exceptionHandler.getClass().getName()).endsWith("ExceptionResolversExceptionHandler");
assertThat(exceptionHandler).extracting("resolvers").asList().hasSize(2);
});
});
}

Loading…
Cancel
Save