Skip to content

Commit 7f61872

Browse files
committed
Update to graphql-java 4.1 (fixes #40)
1 parent eb08e16 commit 7f61872

File tree

8 files changed

+57
-79
lines changed

8 files changed

+57
-79
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656
compile 'commons-fileupload:commons-fileupload:1.3.1'
5757

5858
// GraphQL
59-
compile 'com.graphql-java:graphql-java:3.0.0'
59+
compile 'com.graphql-java:graphql-java:4.1'
6060

6161
compileOnly 'com.graphql-java:graphql-java-annotations:0.13.1'
6262
testCompile 'com.graphql-java:graphql-java-annotations:0.13.1'

src/main/java/graphql/servlet/DefaultExecutionStrategyProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515
package graphql.servlet;
1616

17+
import graphql.execution.AsyncExecutionStrategy;
1718
import graphql.execution.ExecutionStrategy;
18-
import graphql.execution.SimpleExecutionStrategy;
1919

2020
/**
2121
* @author Andrew Potter
@@ -41,7 +41,7 @@ public DefaultExecutionStrategyProvider(ExecutionStrategy queryExecutionStrategy
4141
}
4242

4343
private ExecutionStrategy defaultIfNull(ExecutionStrategy executionStrategy) {
44-
return defaultIfNull(executionStrategy, new SimpleExecutionStrategy());
44+
return defaultIfNull(executionStrategy, new AsyncExecutionStrategy());
4545
}
4646

4747
private ExecutionStrategy defaultIfNull(ExecutionStrategy executionStrategy, ExecutionStrategy defaultStrategy) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.servlet;
16+
17+
import javax.servlet.http.HttpServletRequest;
18+
import javax.servlet.http.HttpServletResponse;
19+
import java.util.Optional;
20+
21+
public class DefaultGraphQLRootObjectBuilder implements GraphQLRootObjectBuilder {
22+
@Override
23+
public Object build(Optional<HttpServletRequest> req, Optional<HttpServletResponse> resp) {
24+
return new Object();
25+
}
26+
}

src/main/java/graphql/servlet/EnhancedExecutionStrategyProvider.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2016 Yurii Rashkovskii
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
*/
15+
package graphql.servlet;
16+
17+
import javax.servlet.http.HttpServletRequest;
18+
import javax.servlet.http.HttpServletResponse;
19+
import java.util.Optional;
20+
21+
public interface GraphQLRootObjectBuilder {
22+
Object build(Optional<HttpServletRequest> req, Optional<HttpServletResponse> resp);
23+
}

src/main/java/graphql/servlet/GraphQLServlet.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,16 @@
1414
*/
1515
package graphql.servlet;
1616

17-
import com.fasterxml.jackson.core.JsonGenerator;
1817
import com.fasterxml.jackson.core.JsonParser;
19-
import com.fasterxml.jackson.core.JsonProcessingException;
2018
import com.fasterxml.jackson.core.type.TypeReference;
2119
import com.fasterxml.jackson.databind.DeserializationContext;
2220
import com.fasterxml.jackson.databind.JsonDeserializer;
23-
import com.fasterxml.jackson.databind.JsonSerializer;
2421
import com.fasterxml.jackson.databind.ObjectMapper;
25-
import com.fasterxml.jackson.databind.RuntimeJsonMappingException;
2622
import com.fasterxml.jackson.databind.SerializationFeature;
27-
import com.fasterxml.jackson.databind.SerializerProvider;
2823
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
29-
import com.fasterxml.jackson.databind.module.SimpleModule;
3024
import graphql.ExecutionResult;
3125
import graphql.GraphQL;
3226
import graphql.GraphQLError;
33-
import graphql.execution.TypeInfo;
3427
import graphql.execution.instrumentation.Instrumentation;
3528
import graphql.introspection.IntrospectionQuery;
3629
import graphql.schema.GraphQLFieldDefinition;
@@ -75,16 +68,7 @@ public abstract class GraphQLServlet extends HttpServlet implements Servlet, Gra
7568
public static final int STATUS_OK = 200;
7669
public static final int STATUS_BAD_REQUEST = 400;
7770

78-
private static final ObjectMapper mapper = new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).registerModule(new SimpleModule().addSerializer(TypeInfo.class, new JsonSerializer<TypeInfo>() {
79-
@Override
80-
public void serialize(TypeInfo value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
81-
gen.writeStartObject();
82-
serializers.defaultSerializeField("type", value.type(), gen);
83-
serializers.defaultSerializeField("parentTypeInfo", value.parentTypeInfo(), gen);
84-
serializers.defaultSerializeField("typeIsNonNull", value.typeIsNonNull(), gen);
85-
gen.writeEndObject();
86-
}
87-
}));
71+
private static final ObjectMapper mapper = new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
8872

8973
protected abstract GraphQLSchemaProvider getSchemaProvider();
9074
protected abstract GraphQLContext createContext(Optional<HttpServletRequest> request, Optional<HttpServletResponse> response);

src/main/java/graphql/servlet/OsgiGraphQLServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class OsgiGraphQLServlet extends GraphQLServlet {
4646
private final List<GraphQLTypesProvider> typesProviders = new ArrayList<>();
4747

4848
private GraphQLContextBuilder contextBuilder = new DefaultGraphQLContextBuilder();
49-
private ExecutionStrategyProvider executionStrategyProvider = new EnhancedExecutionStrategyProvider();
49+
private ExecutionStrategyProvider executionStrategyProvider = new DefaultExecutionStrategyProvider();
5050
private InstrumentationProvider instrumentationProvider = new NoOpInstrumentationProvider();
5151
private GraphQLErrorHandler errorHandler = new DefaultGraphQLErrorHandler();
5252

@@ -164,7 +164,7 @@ public void setExecutionStrategyProvider(ExecutionStrategyProvider provider) {
164164
executionStrategyProvider = provider;
165165
}
166166
public void unsetExecutionStrategyProvider(ExecutionStrategyProvider provider) {
167-
executionStrategyProvider = new EnhancedExecutionStrategyProvider();
167+
executionStrategyProvider = new DefaultExecutionStrategyProvider();
168168
}
169169

170170
@Reference(cardinality = ReferenceCardinality.OPTIONAL)

src/test/groovy/graphql/servlet/GraphQLServletSpec.groovy

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package graphql.servlet
1616

1717
import com.fasterxml.jackson.databind.ObjectMapper
1818
import graphql.Scalars
19-
import graphql.execution.TypeInfo
19+
import graphql.execution.ExecutionTypeInfo
2020
import graphql.schema.DataFetcher
2121
import graphql.schema.GraphQLFieldDefinition
2222
import graphql.schema.GraphQLNonNull
@@ -419,25 +419,8 @@ class GraphQLServletSpec extends Specification {
419419
resp.errors != null
420420
}
421421

422-
def "NonNullableFieldWasNullException is masked by default"() {
423-
setup:
424-
request.addParameter('query', 'query { returnsNullIncorrectly }')
425-
426-
when:
427-
servlet.doGet(request, response)
428-
429-
then:
430-
response.getStatus() == STATUS_OK
431-
response.getContentType() == CONTENT_TYPE_JSON_UTF8
432-
def resp = getResponseContent()
433-
resp.containsKey("data")
434-
resp.data == null
435-
resp.errors != null
436-
resp.errors.first().message.contains('Internal Server Error')
437-
}
438-
439422
def "typeInfo is serialized correctly"() {
440423
expect:
441-
GraphQLServlet.mapper.writeValueAsString(TypeInfo.newTypeInfo().type(new GraphQLNonNull(Scalars.GraphQLString)).build()) != "{}"
424+
GraphQLServlet.mapper.writeValueAsString(ExecutionTypeInfo.newTypeInfo().type(new GraphQLNonNull(Scalars.GraphQLString)).build()) != "{}"
442425
}
443426
}

0 commit comments

Comments
 (0)