Add DataFetcherExceptionResolver mechanism

- Support for one or more DataFetcherExceptionResolver beans
- ErrorType enum with common error categories
- Default handling of unresolved exceptions as ErrorType.INTERNAL_ERROR

Closes gh-51
This commit is contained in:
Rossen Stoyanchev
2021-05-14 10:15:19 +01:00
parent de8e2540b7
commit 3792de375a
7 changed files with 309 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.graphql.DataFetcherExceptionResolver;
import org.springframework.graphql.support.GraphQLSource;
@Configuration
@@ -56,11 +57,14 @@ public class GraphQLAutoConfiguration {
@Bean
public GraphQLSource.Builder graphQLSourceBuilder(
GraphQLProperties properties, RuntimeWiring runtimeWiring,
ObjectProvider<DataFetcherExceptionResolver> exceptionResolversProvider,
ResourceLoader resourceLoader, ObjectProvider<Instrumentation> instrumentationsProvider) {
String schemaLocation = properties.getSchema().getLocation();
return GraphQLSource.builder()
.schemaResource(resourceLoader.getResource(schemaLocation))
.runtimeWiring(runtimeWiring)
.exceptionResolvers(exceptionResolversProvider.orderedStream().collect(Collectors.toList()))
.instrumentation(instrumentationsProvider.orderedStream().collect(Collectors.toList()));
}
}