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

Fix @ExceptionHandler #318

Closed
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
2 changes: 1 addition & 1 deletion graphql-kickstart-spring-support/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,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:$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,9 +17,9 @@ public GraphQLErrorStartupListener(ErrorHandlerSupplier errorHandlerSupplier, bo
}

@Override
public void onApplicationEvent(@NonNull ContextRefreshedEvent event) {
public void onApplicationEvent(@NonNull ApplicationReadyEvent event) {
if (!errorHandlerSupplier.isPresent()) {
ConfigurableApplicationContext context = (ConfigurableApplicationContext) event.getApplicationContext();
ConfigurableApplicationContext context = event.getApplicationContext();
GraphQLErrorHandler errorHandler = new GraphQLErrorHandlerFactory().create(context, exceptionHandlersEnabled);
context.getBeanFactory().registerSingleton(errorHandler.getClass().getCanonicalName(), errorHandler);
errorHandlerSupplier.setErrorHandler(errorHandler);
Expand Down
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