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

Commit 95e9395

Browse files
authored
Merge pull request #263 from jmccaull/upgrade_servlet_version
Update to version of servlet with context settings
2 parents aba616d + fcfd088 commit 95e9395

File tree

23 files changed

+85
-66
lines changed

23 files changed

+85
-66
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ graphql:
172172
corsEnabled: true
173173
# if you want to @ExceptionHandler annotation for custom GraphQLErrors
174174
exception-handlers-enabled: true
175+
contextSetting: PER_REQUEST_WITH_INSTRUMENTATION
175176
```
176177
177178
By default a global CORS filter is enabled for `/graphql/**` context.

example-graphql-tools/src/main/java/com/graphql/sample/boot/GraphQLToolsSampleApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.graphql.sample.boot;
22

33
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
4-
import graphql.servlet.ObjectMapperConfigurer;
4+
import graphql.servlet.config.ObjectMapperConfigurer;
55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
77
import org.springframework.context.annotation.Bean;

example-request-scoped-dataloader/src/main/java/graphql/servlet/examples/dataloader/requestscope/CustomGraphQLContextBuilder.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package graphql.servlet.examples.dataloader.requestscope;
22

3-
import graphql.servlet.GraphQLContext;
4-
import graphql.servlet.GraphQLContextBuilder;
3+
import graphql.servlet.context.DefaultGraphQLContext;
4+
import graphql.servlet.context.DefaultGraphQLServletContext;
5+
import graphql.servlet.context.DefaultGraphQLWebSocketContext;
6+
import graphql.servlet.context.GraphQLContext;
7+
import graphql.servlet.context.GraphQLContextBuilder;
58
import org.dataloader.DataLoader;
69
import org.dataloader.DataLoaderRegistry;
710
import org.springframework.stereotype.Component;
@@ -23,26 +26,17 @@ public CustomGraphQLContextBuilder(CustomerRepository customerRepository) {
2326

2427
@Override
2528
public GraphQLContext build(HttpServletRequest req, HttpServletResponse response) {
26-
GraphQLContext context = new GraphQLContext(req, response);
27-
context.setDataLoaderRegistry(buildDataLoaderRegistry());
28-
29-
return context;
29+
return DefaultGraphQLServletContext.createServletContext(buildDataLoaderRegistry(), null).with(req).with(response).build();
3030
}
3131

3232
@Override
3333
public GraphQLContext build() {
34-
GraphQLContext context = new GraphQLContext();
35-
context.setDataLoaderRegistry(buildDataLoaderRegistry());
36-
37-
return context;
34+
return new DefaultGraphQLContext(buildDataLoaderRegistry(), null);
3835
}
3936

4037
@Override
4138
public GraphQLContext build(Session session, HandshakeRequest request) {
42-
GraphQLContext context = new GraphQLContext(session, request);
43-
context.setDataLoaderRegistry(buildDataLoaderRegistry());
44-
45-
return context;
39+
return DefaultGraphQLWebSocketContext.createWebSocketContext(buildDataLoaderRegistry(), null).with(session).with(request).build();
4640
}
4741

4842
private DataLoaderRegistry buildDataLoaderRegistry() {

example-request-scoped-dataloader/src/main/java/graphql/servlet/examples/dataloader/requestscope/CustomerResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.coxautodev.graphql.tools.GraphQLResolver;
44
import graphql.schema.DataFetchingEnvironment;
5-
import graphql.servlet.GraphQLContext;
5+
import graphql.servlet.context.GraphQLContext;
66
import org.dataloader.DataLoader;
77
import org.springframework.stereotype.Component;
88

example-spring-common/src/main/java/com/oembedler/moon/graphql/boot/sample/schema/TodoSchema.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.oembedler.moon.graphql.engine.stereotype.GraphQLOut;
3333
import com.oembedler.moon.graphql.engine.stereotype.GraphQLSchema;
3434
import com.oembedler.moon.graphql.engine.stereotype.GraphQLSchemaQuery;
35-
import graphql.servlet.GraphQLContext;
35+
import graphql.servlet.context.GraphQLServletContext;
3636
import org.apache.commons.fileupload.FileItem;
3737

3838
import javax.servlet.http.Part;
@@ -155,8 +155,8 @@ TodoObjectType.TodoEdgeObjectType addTodoMutation(@GraphQLIn("addTodoInput") Add
155155
@GraphQLMutation
156156
public
157157
@GraphQLOut("filename")
158-
String uploadFile(GraphQLContext graphQLContext) {
159-
return graphQLContext.getFiles().orElse(new HashMap<>()).values().stream().flatMap(Collection::stream).map(Part::getName).collect(Collectors.joining(", "));
158+
String uploadFile(GraphQLServletContext graphQLContext) {
159+
return graphQLContext.getParts().values().stream().flatMap(Collection::stream).map(Part::getName).collect(Collectors.joining(", "));
160160
}
161161

162162
@GraphQLMutation

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818
#
1919

20-
version = 5.9.1-SNAPSHOT
20+
version = 5.10.0
2121
PROJECT_GROUP = com.graphql-java-kickstart
2222
PROJECT_NAME = graphql-spring-boot
2323
PROJECT_DESC = GraphQL Spring Framework Boot
@@ -39,8 +39,8 @@ TARGET_COMPATIBILITY = 1.8
3939
LIB_GRAPHQL_JAVA_VER = 13.0
4040
LIB_JUNIT_VER = 4.12
4141
LIB_SPRING_CORE_VER = 5.0.4.RELEASE
42-
LIB_SPRING_BOOT_VER = 2.1.5.RELEASE
43-
LIB_GRAPHQL_SERVLET_VER = 7.5.1-SNAPSHOT
42+
LIB_SPRING_BOOT_VER = 2.1.6.RELEASE
43+
LIB_GRAPHQL_SERVLET_VER = 8.0.0
4444
LIB_GRAPHQL_JAVA_TOOLS_VER = 5.6.1
4545
LIB_COMMONS_IO_VER = 2.6
4646
kotlin.version=1.3.31

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/GraphQLJavaToolsAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.fasterxml.jackson.module.kotlin.KotlinModule;
77
import graphql.schema.GraphQLScalarType;
88
import graphql.schema.GraphQLSchema;
9-
import graphql.servlet.GraphQLSchemaProvider;
9+
import graphql.servlet.config.GraphQLSchemaProvider;
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
1212
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/GraphQLServletProperties.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.oembedler.moon.graphql.boot;
2121

22+
import graphql.servlet.context.ContextSetting;
2223
import org.springframework.boot.context.properties.ConfigurationProperties;
2324
import org.springframework.boot.context.properties.NestedConfigurationProperty;
2425
import org.springframework.context.annotation.Configuration;
@@ -38,6 +39,8 @@ public class GraphQLServletProperties {
3839

3940
private long subscriptionTimeout = 0;
4041

42+
private ContextSetting contextSetting = ContextSetting.PER_QUERY_WITH_INSTRUMENTATION;
43+
4144
public String getMapping() {
4245
return mapping != null ? mapping : "/graphql";
4346
}
@@ -105,4 +108,12 @@ public long getSubscriptionTimeout() {
105108
public void setSubscriptionTimeout(long subscriptionTimeout) {
106109
this.subscriptionTimeout = subscriptionTimeout;
107110
}
111+
112+
public ContextSetting getContextSetting() {
113+
return contextSetting;
114+
}
115+
116+
public void setContextSetting(ContextSetting contextSetting) {
117+
this.contextSetting = contextSetting;
118+
}
108119
}

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/GraphQLWebAutoConfiguration.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@
3131
import graphql.execution.preparsed.PreparsedDocumentProvider;
3232
import graphql.schema.GraphQLSchema;
3333
import graphql.servlet.AbstractGraphQLHttpServlet;
34-
import graphql.servlet.BatchExecutionHandler;
35-
import graphql.servlet.DefaultExecutionStrategyProvider;
36-
import graphql.servlet.DefaultGraphQLSchemaProvider;
37-
import graphql.servlet.ExecutionStrategyProvider;
38-
import graphql.servlet.GraphQLConfiguration;
39-
import graphql.servlet.GraphQLContextBuilder;
40-
import graphql.servlet.GraphQLErrorHandler;
4134
import graphql.servlet.GraphQLHttpServlet;
42-
import graphql.servlet.GraphQLInvocationInputFactory;
43-
import graphql.servlet.GraphQLObjectMapper;
44-
import graphql.servlet.GraphQLQueryInvoker;
45-
import graphql.servlet.GraphQLRootObjectBuilder;
46-
import graphql.servlet.GraphQLSchemaProvider;
47-
import graphql.servlet.GraphQLServletListener;
48-
import graphql.servlet.ObjectMapperConfigurer;
49-
import graphql.servlet.ObjectMapperProvider;
35+
import graphql.servlet.config.DefaultExecutionStrategyProvider;
36+
import graphql.servlet.config.DefaultGraphQLSchemaProvider;
37+
import graphql.servlet.config.ExecutionStrategyProvider;
38+
import graphql.servlet.config.GraphQLConfiguration;
39+
import graphql.servlet.config.GraphQLSchemaProvider;
40+
import graphql.servlet.config.ObjectMapperConfigurer;
41+
import graphql.servlet.config.ObjectMapperProvider;
42+
import graphql.servlet.context.GraphQLContextBuilder;
43+
import graphql.servlet.core.GraphQLErrorHandler;
44+
import graphql.servlet.core.GraphQLObjectMapper;
45+
import graphql.servlet.core.GraphQLQueryInvoker;
46+
import graphql.servlet.core.GraphQLRootObjectBuilder;
47+
import graphql.servlet.core.GraphQLServletListener;
48+
import graphql.servlet.input.BatchInputPreProcessor;
49+
import graphql.servlet.input.GraphQLInvocationInputFactory;
5050
import lombok.extern.slf4j.Slf4j;
5151
import org.springframework.beans.factory.ObjectProvider;
5252
import org.springframework.beans.factory.annotation.Autowired;
@@ -73,7 +73,7 @@
7373
import java.util.Map;
7474
import java.util.Optional;
7575

76-
import static graphql.servlet.GraphQLObjectMapper.newBuilder;
76+
import static graphql.servlet.core.GraphQLObjectMapper.*;
7777

7878

7979
/**
@@ -127,7 +127,7 @@ public class GraphQLWebAutoConfiguration {
127127
private MultipartConfigElement multipartConfigElement;
128128

129129
@Autowired(required = false)
130-
private BatchExecutionHandler batchExecutionHandler;
130+
private BatchInputPreProcessor batchInputPreProcessor;
131131

132132
@PostConstruct
133133
void postConstruct() {
@@ -228,10 +228,6 @@ public GraphQLQueryInvoker queryInvoker(ExecutionStrategyProvider executionStrat
228228
builder.withPreparsedDocumentProvider(preparsedDocumentProvider);
229229
}
230230

231-
if (batchExecutionHandler != null) {
232-
builder.withBatchExeuctionHandler(batchExecutionHandler);
233-
}
234-
235231
return builder.build();
236232
}
237233

@@ -273,6 +269,8 @@ public GraphQLConfiguration graphQLServletConfiguration(GraphQLInvocationInputFa
273269
.with(listeners)
274270
.with(graphQLServletProperties.isAsyncModeEnabled())
275271
.with(graphQLServletProperties.getSubscriptionTimeout())
272+
.with(batchInputPreProcessor)
273+
.with(graphQLServletProperties.getContextSetting())
276274
.build();
277275
}
278276

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/GraphQLWebsocketAutoConfiguration.java

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

3-
import graphql.servlet.ApolloSubscriptionConnectionListener;
4-
import graphql.servlet.GraphQLInvocationInputFactory;
5-
import graphql.servlet.GraphQLObjectMapper;
6-
import graphql.servlet.GraphQLQueryInvoker;
73
import graphql.servlet.GraphQLWebsocketServlet;
8-
import graphql.servlet.SubscriptionConnectionListener;
4+
import graphql.servlet.core.ApolloSubscriptionConnectionListener;
5+
import graphql.servlet.core.GraphQLObjectMapper;
6+
import graphql.servlet.core.GraphQLQueryInvoker;
7+
import graphql.servlet.core.SubscriptionConnectionListener;
8+
import graphql.servlet.input.GraphQLInvocationInputFactory;
99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.beans.factory.annotation.Value;
1111
import org.springframework.boot.autoconfigure.AutoConfigureAfter;

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/OnSchemaOrSchemaProviderBean.java

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

33
import graphql.schema.GraphQLSchema;
4-
import graphql.servlet.GraphQLSchemaProvider;
4+
import graphql.servlet.config.GraphQLSchemaProvider;
55
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
66
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
77

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/error/ErrorHandlerSupplier.java

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

3-
import graphql.servlet.GraphQLErrorHandler;
3+
import graphql.servlet.core.GraphQLErrorHandler;
44

55
import java.util.Objects;
66
import java.util.function.Supplier;

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/error/GraphQLErrorFromExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import graphql.GraphQLError;
55
import graphql.GraphQLException;
66
import graphql.SerializationError;
7-
import graphql.servlet.DefaultGraphQLErrorHandler;
8-
import graphql.servlet.GenericGraphQLError;
7+
import graphql.servlet.core.DefaultGraphQLErrorHandler;
8+
import graphql.servlet.core.GenericGraphQLError;
99
import lombok.extern.slf4j.Slf4j;
1010

1111
import java.util.HashMap;

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/error/GraphQLErrorHandlerFactory.java

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

33
import graphql.GraphQLError;
4-
import graphql.servlet.DefaultGraphQLErrorHandler;
5-
import graphql.servlet.GraphQLErrorHandler;
4+
import graphql.servlet.core.DefaultGraphQLErrorHandler;
5+
import graphql.servlet.core.GraphQLErrorHandler;
66
import lombok.extern.slf4j.Slf4j;
77
import org.springframework.beans.factory.BeanCreationException;
88
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/error/GraphQLErrorStartupListener.java

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

3-
import graphql.servlet.GraphQLErrorHandler;
3+
import graphql.servlet.core.GraphQLErrorHandler;
44
import org.springframework.context.ApplicationListener;
55
import org.springframework.context.ConfigurableApplicationContext;
66
import org.springframework.context.event.ContextRefreshedEvent;

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/error/ReflectiveGraphQLErrorFactory.java

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

33
import graphql.GraphQLError;
4-
import graphql.servlet.GenericGraphQLError;
4+
import graphql.servlet.core.GenericGraphQLError;
55
import lombok.extern.slf4j.Slf4j;
66
import org.springframework.web.bind.annotation.ExceptionHandler;
77

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/error/ThrowableGraphQLError.java

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

3-
import graphql.servlet.GenericGraphQLError;
3+
import graphql.servlet.core.GenericGraphQLError;
44

55
import java.util.Objects;
66

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
import graphql.GraphQLError;
1010
import graphql.schema.GraphQLObjectType;
1111
import graphql.schema.GraphQLSchema;
12-
import graphql.servlet.GenericGraphQLError;
13-
import graphql.servlet.GraphQLErrorHandler;
14-
import graphql.servlet.GraphQLObjectMapper;
12+
import graphql.servlet.core.GraphQLErrorHandler;
13+
import graphql.servlet.core.GraphQLObjectMapper;
1514
import org.junit.Before;
1615
import org.junit.Test;
1716
import org.springframework.context.annotation.Bean;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.oembedler.moon.graphql.boot;
22

3+
import graphql.servlet.context.ContextSetting;
34
import org.junit.Test;
45
import org.junit.runner.RunWith;
56
import org.springframework.beans.factory.annotation.Autowired;
@@ -10,7 +11,7 @@
1011
import static org.junit.Assert.assertEquals;
1112

1213
@RunWith(SpringRunner.class)
13-
@SpringBootTest(properties = {"graphql.servlet.mapping=/test"})
14+
@SpringBootTest(properties = {"graphql.servlet.mapping=/test", "graphql.servlet.contextSetting=PER_REQUEST_WITH_INSTRUMENTATION"})
1415
public class GraphQLServletPropertiesTest {
1516

1617
@Autowired
@@ -23,4 +24,9 @@ public void contains_custom_servlet_endpoint() {
2324
assertEquals("/test", mapping);
2425
}
2526

27+
@Test
28+
public void containsCorrectContextSetting() {
29+
ContextSetting contextSetting = properties.getContextSetting();
30+
assertEquals(ContextSetting.PER_REQUEST_WITH_INSTRUMENTATION, contextSetting);
31+
}
2632
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import graphql.schema.GraphQLObjectType;
1111
import graphql.schema.GraphQLSchema;
1212
import graphql.servlet.AbstractGraphQLHttpServlet;
13-
import graphql.servlet.DefaultGraphQLSchemaProvider;
14-
import graphql.servlet.GraphQLSchemaProvider;
13+
import graphql.servlet.config.DefaultGraphQLSchemaProvider;
14+
import graphql.servlet.config.GraphQLSchemaProvider;
1515
import org.junit.Assert;
1616
import org.junit.Test;
1717
import org.springframework.context.annotation.Bean;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
graphql.servlet.mapping: /test
1+
graphql.servlet.mapping: /test

graphql-spring-boot-test-autoconfigure/src/main/java/com/graphql/spring/boot/test/GraphQLTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
import graphql.schema.GraphQLSchema;
1414
import graphql.schema.idl.SchemaParser;
1515
import graphql.servlet.*;
16+
import graphql.servlet.config.ExecutionStrategyProvider;
17+
import graphql.servlet.config.GraphQLSchemaProvider;
18+
import graphql.servlet.config.ObjectMapperConfigurer;
19+
import graphql.servlet.context.GraphQLContextBuilder;
20+
import graphql.servlet.core.GraphQLErrorHandler;
21+
import graphql.servlet.core.GraphQLObjectMapper;
22+
import graphql.servlet.core.GraphQLQueryInvoker;
23+
import graphql.servlet.core.GraphQLRootObjectBuilder;
24+
import graphql.servlet.core.GraphQLServletListener;
25+
import graphql.servlet.input.GraphQLInvocationInputFactory;
1626
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
1727
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
1828
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;

graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import graphql.ExecutionResult;
77
import graphql.GraphQL;
88
import graphql.GraphQLError;
9-
import graphql.servlet.GraphQLObjectMapper;
9+
import graphql.servlet.core.GraphQLObjectMapper;
1010
import lombok.extern.slf4j.Slf4j;
1111

1212
import java.util.HashMap;

0 commit comments

Comments
 (0)