Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 3d9f9c7

Browse files
authored
Merge pull request #305 from solidline/graphql-error-startup-listener-supplier
Allow errorHandlerSupplier to re-init
2 parents 08395c9 + 1c30ed4 commit 3d9f9c7

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

graphql-kickstart-spring-support/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ dependencies {
22
compileOnly "com.graphql-java-kickstart:graphql-java-kickstart:$LIB_GRAPHQL_SERVLET_VER"
33
compileOnly "org.springframework:spring-web:$LIB_SPRING_CORE_VER"
44
compileOnly "org.springframework:spring-context:$LIB_SPRING_CORE_VER"
5+
compileOnly "org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER"
56

67
testCompile "com.graphql-java-kickstart:graphql-java-kickstart:$LIB_GRAPHQL_SERVLET_VER"
78
testCompile "com.graphql-java:graphql-java:$LIB_GRAPHQL_JAVA_VER"
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package graphql.kickstart.spring.error;
22

33
import graphql.kickstart.execution.error.GraphQLErrorHandler;
4+
import org.springframework.boot.context.event.ApplicationReadyEvent;
45
import org.springframework.context.ApplicationListener;
56
import org.springframework.context.ConfigurableApplicationContext;
6-
import org.springframework.context.event.ContextRefreshedEvent;
77
import org.springframework.lang.NonNull;
88

9-
public class GraphQLErrorStartupListener implements ApplicationListener<ContextRefreshedEvent> {
9+
public class GraphQLErrorStartupListener implements ApplicationListener<ApplicationReadyEvent> {
1010

1111
private final ErrorHandlerSupplier errorHandlerSupplier;
1212
private final boolean exceptionHandlersEnabled;
@@ -17,13 +17,10 @@ public GraphQLErrorStartupListener(ErrorHandlerSupplier errorHandlerSupplier, bo
1717
}
1818

1919
@Override
20-
public void onApplicationEvent(@NonNull ContextRefreshedEvent event) {
21-
if (!errorHandlerSupplier.isPresent()) {
22-
ConfigurableApplicationContext context = (ConfigurableApplicationContext) event.getApplicationContext();
23-
GraphQLErrorHandler errorHandler = new GraphQLErrorHandlerFactory().create(context, exceptionHandlersEnabled);
24-
context.getBeanFactory().registerSingleton(errorHandler.getClass().getCanonicalName(), errorHandler);
25-
errorHandlerSupplier.setErrorHandler(errorHandler);
26-
}
20+
public void onApplicationEvent(@NonNull ApplicationReadyEvent event) {
21+
ConfigurableApplicationContext context = event.getApplicationContext();
22+
GraphQLErrorHandler errorHandler = new GraphQLErrorHandlerFactory().create(context, exceptionHandlersEnabled);
23+
context.getBeanFactory().registerSingleton(errorHandler.getClass().getCanonicalName(), errorHandler);
24+
errorHandlerSupplier.setErrorHandler(errorHandler);
2725
}
28-
2926
}

graphql-spring-boot-autoconfigure/src/test/java/com/oembedler/moon/graphql/boot/test/AbstractAutoConfigurationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.oembedler.moon.graphql.boot.test;
22

33
import org.junit.After;
4+
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
6+
import org.springframework.boot.context.event.ApplicationReadyEvent;
57
import org.springframework.boot.test.util.TestPropertyValues;
68
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
79
import org.springframework.context.annotation.AnnotationConfigRegistry;
@@ -59,6 +61,7 @@ protected void load(Class<?> config, String... environment) {
5961

6062
loadServletContext();
6163
getContext().refresh();
64+
getContext().publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], getContext()));
6265
}
6366

6467
private void loadServletContext() {

0 commit comments

Comments
 (0)