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

Allow errorHandlerSupplier to re-init #305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions graphql-kickstart-spring-support/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dependencies {
compileOnly "com.graphql-java-kickstart:graphql-java-kickstart:$LIB_GRAPHQL_SERVLET_VER"
compileOnly "org.springframework:spring-web:$LIB_SPRING_CORE_VER"
compileOnly "org.springframework:spring-context:$LIB_SPRING_CORE_VER"
compileOnly "org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER"

testCompile "com.graphql-java-kickstart:graphql-java-kickstart:$LIB_GRAPHQL_SERVLET_VER"
testCompile "com.graphql-java:graphql-java:$LIB_GRAPHQL_JAVA_VER"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package graphql.kickstart.spring.error;

import graphql.kickstart.execution.error.GraphQLErrorHandler;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.lang.NonNull;

public class GraphQLErrorStartupListener implements ApplicationListener<ContextRefreshedEvent> {
public class GraphQLErrorStartupListener implements ApplicationListener<ApplicationReadyEvent> {

private final ErrorHandlerSupplier errorHandlerSupplier;
private final boolean exceptionHandlersEnabled;
Expand All @@ -17,13 +17,10 @@ public GraphQLErrorStartupListener(ErrorHandlerSupplier errorHandlerSupplier, bo
}

@Override
public void onApplicationEvent(@NonNull ContextRefreshedEvent event) {
if (!errorHandlerSupplier.isPresent()) {
ConfigurableApplicationContext context = (ConfigurableApplicationContext) event.getApplicationContext();
GraphQLErrorHandler errorHandler = new GraphQLErrorHandlerFactory().create(context, exceptionHandlersEnabled);
context.getBeanFactory().registerSingleton(errorHandler.getClass().getCanonicalName(), errorHandler);
errorHandlerSupplier.setErrorHandler(errorHandler);
}
public void onApplicationEvent(@NonNull ApplicationReadyEvent event) {
ConfigurableApplicationContext context = event.getApplicationContext();
GraphQLErrorHandler errorHandler = new GraphQLErrorHandlerFactory().create(context, exceptionHandlersEnabled);
context.getBeanFactory().registerSingleton(errorHandler.getClass().getCanonicalName(), errorHandler);
errorHandlerSupplier.setErrorHandler(errorHandler);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.oembedler.moon.graphql.boot.test;

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

loadServletContext();
getContext().refresh();
getContext().publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], getContext()));
}

private void loadServletContext() {
Expand Down