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

Commit 5316fba

Browse files
committed
Move error handlers to be reused by webflux starter too
1 parent 3ae2c10 commit 5316fba

File tree

16 files changed

+50
-35
lines changed

16 files changed

+50
-35
lines changed

graphql-kickstart-spring-boot-autoconfigure-webflux/src/main/java/graphql/kickstart/spring/webflux/boot/GraphQLSpringWebfluxAutoConfiguration.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import graphql.kickstart.execution.subscriptions.GraphQLSubscriptionInvocationInputFactory;
1111
import graphql.kickstart.execution.subscriptions.apollo.ApolloSubscriptionConnectionListener;
1212
import graphql.kickstart.execution.subscriptions.apollo.KeepAliveSubscriptionConnectionListener;
13+
import graphql.kickstart.spring.error.ErrorHandlerSupplier;
14+
import graphql.kickstart.spring.error.GraphQLErrorStartupListener;
1315
import graphql.kickstart.spring.webflux.DefaultGraphQLSpringWebfluxContextBuilder;
1416
import graphql.kickstart.spring.webflux.DefaultGraphQLSpringWebfluxRootObjectBuilder;
1517
import graphql.kickstart.spring.webflux.GraphQLController;
@@ -45,9 +47,20 @@ public class GraphQLSpringWebfluxAutoConfiguration {
4547

4648
@Bean
4749
@ConditionalOnMissingBean
48-
public GraphQLObjectMapper graphQLObjectMapper(ObjectProvider<ObjectMapperProvider> provider) {
50+
public ErrorHandlerSupplier errorHandlerSupplier() {
51+
return new ErrorHandlerSupplier(null);
52+
}
53+
54+
@Bean
55+
public GraphQLErrorStartupListener graphQLErrorStartupListener(ErrorHandlerSupplier errorHandlerSupplier) {
56+
return new GraphQLErrorStartupListener(errorHandlerSupplier, true);
57+
}
58+
59+
@Bean
60+
@ConditionalOnMissingBean
61+
public GraphQLObjectMapper graphQLObjectMapper(ObjectProvider<ObjectMapperProvider> provider, ErrorHandlerSupplier errorHandlerSupplier) {
4962
GraphQLObjectMapper.Builder builder = newBuilder();
50-
// builder.withGraphQLErrorHandler(errorHandlerSupplier);
63+
builder.withGraphQLErrorHandler(errorHandlerSupplier);
5164
provider.ifAvailable(builder::withObjectMapperProvider);
5265
return builder.build();
5366
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
dependencies {
22
compileOnly "com.graphql-java-kickstart:graphql-java-kickstart:$LIB_GRAPHQL_SERVLET_VER"
33
compileOnly "org.springframework:spring-web:$LIB_SPRING_CORE_VER"
4+
compileOnly "org.springframework:spring-context:$LIB_SPRING_CORE_VER"
5+
6+
testCompile "com.graphql-java-kickstart:graphql-java-kickstart:$LIB_GRAPHQL_SERVLET_VER"
7+
testCompile "com.graphql-java:graphql-java:$LIB_GRAPHQL_JAVA_VER"
8+
testCompile "org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER"
9+
testCompile "org.springframework.boot:spring-boot-starter-test:$LIB_SPRING_BOOT_VER"
10+
testCompile(project(":graphql-spring-boot-test"))
411
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

33
import graphql.kickstart.execution.error.GraphQLErrorHandler;
44
import java.util.Objects;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

33
import graphql.GraphQLError;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

33
import static java.util.Collections.singletonList;
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

3-
import static com.oembedler.moon.graphql.boot.error.GraphQLErrorFactory.withReflection;
3+
import static graphql.kickstart.spring.error.GraphQLErrorFactory.withReflection;
44
import static java.util.Collections.emptyList;
55
import static java.util.stream.Collectors.toList;
66

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

33
import graphql.kickstart.execution.error.GraphQLErrorHandler;
4-
import javax.validation.constraints.NotNull;
54
import org.springframework.context.ApplicationListener;
65
import org.springframework.context.ConfigurableApplicationContext;
76
import org.springframework.context.event.ContextRefreshedEvent;
7+
import org.springframework.lang.NonNull;
88

99
public class GraphQLErrorStartupListener implements ApplicationListener<ContextRefreshedEvent> {
1010

@@ -17,7 +17,7 @@ public GraphQLErrorStartupListener(ErrorHandlerSupplier errorHandlerSupplier, bo
1717
}
1818

1919
@Override
20-
public void onApplicationEvent(@NotNull ContextRefreshedEvent event) {
20+
public void onApplicationEvent(@NonNull ContextRefreshedEvent event) {
2121
if (!errorHandlerSupplier.isPresent()) {
2222
ConfigurableApplicationContext context = (ConfigurableApplicationContext) event.getApplicationContext();
2323
GraphQLErrorHandler errorHandler = new GraphQLErrorHandlerFactory().create(context, exceptionHandlersEnabled);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

33
import static java.util.Collections.singletonList;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

33
import graphql.GraphQLError;
44
import java.lang.reflect.Method;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.error;
1+
package graphql.kickstart.spring.error;
22

33
import java.util.Comparator;
44

0 commit comments

Comments
 (0)