|
22 | 22 | import com.fasterxml.jackson.databind.InjectableValues; |
23 | 23 | import com.fasterxml.jackson.databind.ObjectMapper; |
24 | 24 | import com.oembedler.moon.graphql.boot.error.ErrorHandlerSupplier; |
25 | | -import com.oembedler.moon.graphql.boot.error.GraphQLErrorHandlerFactory; |
| 25 | +import com.oembedler.moon.graphql.boot.error.GraphQLErrorStartupListener; |
26 | 26 | import com.oembedler.moon.graphql.boot.metrics.MetricsInstrumentation; |
27 | 27 | import graphql.execution.AsyncExecutionStrategy; |
28 | 28 | import graphql.execution.ExecutionStrategy; |
|
48 | 48 | import graphql.servlet.ObjectMapperConfigurer; |
49 | 49 | import graphql.servlet.ObjectMapperProvider; |
50 | 50 | import lombok.extern.slf4j.Slf4j; |
51 | | -import org.springframework.beans.BeansException; |
52 | 51 | import org.springframework.beans.factory.ObjectProvider; |
53 | 52 | import org.springframework.beans.factory.annotation.Autowired; |
54 | 53 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; |
|
60 | 59 | import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; |
61 | 60 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
62 | 61 | import org.springframework.boot.web.servlet.ServletRegistrationBean; |
63 | | -import org.springframework.context.ApplicationContext; |
64 | | -import org.springframework.context.ApplicationContextAware; |
65 | | -import org.springframework.context.ConfigurableApplicationContext; |
66 | 62 | import org.springframework.context.annotation.Bean; |
67 | 63 | import org.springframework.context.annotation.Configuration; |
68 | 64 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
69 | 65 | import org.springframework.web.filter.CorsFilter; |
70 | 66 | import org.springframework.web.servlet.DispatcherServlet; |
71 | 67 | import org.springframework.web.servlet.config.annotation.CorsRegistryWorkaround; |
72 | 68 |
|
| 69 | +import javax.annotation.PostConstruct; |
73 | 70 | import javax.servlet.MultipartConfigElement; |
74 | 71 | import java.util.List; |
75 | 72 | import java.util.Map; |
|
89 | 86 | @ConditionalOnProperty(value = "graphql.servlet.enabled", havingValue = "true", matchIfMissing = true) |
90 | 87 | @AutoConfigureAfter({GraphQLJavaToolsAutoConfiguration.class, JacksonAutoConfiguration.class}) |
91 | 88 | @EnableConfigurationProperties({GraphQLServletProperties.class}) |
92 | | -public class GraphQLWebAutoConfiguration implements ApplicationContextAware { |
| 89 | +public class GraphQLWebAutoConfiguration { |
93 | 90 |
|
94 | 91 | public static final String QUERY_EXECUTION_STRATEGY = "queryExecutionStrategy"; |
95 | 92 | public static final String MUTATION_EXECUTION_STRATEGY = "mutationExecutionStrategy"; |
@@ -130,14 +127,16 @@ public class GraphQLWebAutoConfiguration implements ApplicationContextAware { |
130 | 127 | @Autowired(required = false) |
131 | 128 | private BatchExecutionHandler batchExecutionHandler; |
132 | 129 |
|
133 | | - @Override |
134 | | - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
135 | | - if (errorHandler == null) { |
136 | | - ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext; |
137 | | - errorHandler = new GraphQLErrorHandlerFactory().create(context, graphQLServletProperties.isExceptionHandlersEnabled()); |
138 | | - context.getBeanFactory().registerSingleton(errorHandler.getClass().getCanonicalName(), errorHandler); |
| 130 | + @PostConstruct |
| 131 | + void postConstruct() { |
| 132 | + if (errorHandler != null) { |
| 133 | + errorHandlerSupplier.setErrorHandler(errorHandler); |
139 | 134 | } |
140 | | - errorHandlerSupplier.setErrorHandler(errorHandler); |
| 135 | + } |
| 136 | + |
| 137 | + @Bean |
| 138 | + public GraphQLErrorStartupListener graphQLErrorStartupListener() { |
| 139 | + return new GraphQLErrorStartupListener(errorHandlerSupplier, graphQLServletProperties.isExceptionHandlersEnabled()); |
141 | 140 | } |
142 | 141 |
|
143 | 142 | @Bean |
@@ -263,12 +262,12 @@ public ObjectMapperProvider objectMapperProvider(ObjectMapper objectMapper) { |
263 | 262 | @ConditionalOnMissingBean |
264 | 263 | public GraphQLConfiguration graphQLServletConfiguration(GraphQLInvocationInputFactory invocationInputFactory, GraphQLQueryInvoker queryInvoker, GraphQLObjectMapper graphQLObjectMapper) { |
265 | 264 | return GraphQLConfiguration.with(invocationInputFactory) |
266 | | - .with(queryInvoker) |
267 | | - .with(graphQLObjectMapper) |
268 | | - .with(listeners) |
269 | | - .with(graphQLServletProperties.isAsyncModeEnabled()) |
270 | | - .with(graphQLServletProperties.getSubscriptionTimeout()) |
271 | | - .build(); |
| 265 | + .with(queryInvoker) |
| 266 | + .with(graphQLObjectMapper) |
| 267 | + .with(listeners) |
| 268 | + .with(graphQLServletProperties.isAsyncModeEnabled()) |
| 269 | + .with(graphQLServletProperties.getSubscriptionTimeout()) |
| 270 | + .build(); |
272 | 271 | } |
273 | 272 |
|
274 | 273 | @Bean |
|
0 commit comments