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

Commit 638808d

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 5046974 + cb13fb7 commit 638808d

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ graphql.playground:
293293
mapping: /playground
294294
endpoint: /graphql
295295
subscriptionsEndpoint: /subscriptions
296-
staticFolder.basePath: my-playground-resources-folder
296+
staticPath.base: my-playground-resources-folder
297297
enabled: true
298298
pageTitle: Playground
299299
cdn:

graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/error/GraphQLErrorStartupListener.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public GraphQLErrorStartupListener(ErrorHandlerSupplier errorHandlerSupplier, bo
1818

1919
@Override
2020
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);
21+
if (!errorHandlerSupplier.isPresent()) {
22+
ConfigurableApplicationContext context = event.getApplicationContext();
23+
GraphQLErrorHandler errorHandler = new GraphQLErrorHandlerFactory().create(context, exceptionHandlersEnabled);
24+
context.getBeanFactory().registerSingleton(errorHandler.getClass().getCanonicalName(), errorHandler);
25+
errorHandlerSupplier.setErrorHandler(errorHandler);
26+
}
2527
}
2628
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package graphql.kickstart.spring.error;
2+
3+
import graphql.kickstart.execution.error.GraphQLErrorHandler;
4+
import org.assertj.core.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
import org.mockito.Mockito;
7+
import org.springframework.boot.SpringApplication;
8+
import org.springframework.boot.context.event.ApplicationReadyEvent;
9+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
10+
11+
public class GraphQLErrorStartupListenerTest {
12+
13+
@Test
14+
void error_handler_is_not_overridden_when_present() {
15+
GraphQLErrorHandler expectedErrorHandler = Mockito.mock(GraphQLErrorHandler.class);
16+
ErrorHandlerSupplier errorHandlerSupplier = new ErrorHandlerSupplier(expectedErrorHandler);
17+
GraphQLErrorStartupListener graphQLErrorStartupListener = new GraphQLErrorStartupListener(errorHandlerSupplier, false);
18+
graphQLErrorStartupListener.onApplicationEvent(getApplicationReadyEvent());
19+
Assertions.assertThat(errorHandlerSupplier.get()).isEqualTo(expectedErrorHandler);
20+
}
21+
22+
@Test
23+
void error_handler_is_set_when_not_present() {
24+
ErrorHandlerSupplier errorHandlerSupplier = new ErrorHandlerSupplier(null);
25+
GraphQLErrorStartupListener graphQLErrorStartupListener = new GraphQLErrorStartupListener(errorHandlerSupplier, false);
26+
graphQLErrorStartupListener.onApplicationEvent(getApplicationReadyEvent());
27+
Assertions.assertThat(errorHandlerSupplier.get()).isNotNull();
28+
}
29+
30+
private ApplicationReadyEvent getApplicationReadyEvent() {
31+
AnnotationConfigWebApplicationContext annotationConfigWebApplicationContext = new AnnotationConfigWebApplicationContext();
32+
annotationConfigWebApplicationContext.refresh();
33+
return new ApplicationReadyEvent(new SpringApplication(), new String[0], annotationConfigWebApplicationContext);
34+
}
35+
36+
}

0 commit comments

Comments
 (0)