Skip to content

Commit 6bcb638

Browse files
committed
#84 - moves to graphql 3.0.0
1 parent 3bbd32b commit 6bcb638

24 files changed

+537
-224
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ gradle.projectsEvaluated {
6262

6363
dependencies {
6464
compile 'javax.validation:validation-api:1.1.0.Final'
65-
compile 'com.graphql-java:graphql-java:2.2.0'
65+
compile 'com.graphql-java:graphql-java:3.0.0'
6666

6767
// OSGi
6868
compileOnly 'org.osgi:org.osgi.core:6.0.0'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Oct 27 10:18:00 ICT 2016
1+
#Tue Jun 06 14:52:40 AEST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip

src/main/java/graphql/annotations/Connection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
import graphql.schema.DataFetcher;
1818

19-
public interface Connection extends DataFetcher {
19+
public interface Connection<T> extends DataFetcher<T> {
2020
}

src/main/java/graphql/annotations/DefaultTypeFunction.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -45,6 +45,7 @@
4545
import java.util.stream.Collectors;
4646
import java.util.stream.Stream;
4747

48+
import static graphql.annotations.util.NamingKit.toGraphqlName;
4849
import static graphql.schema.GraphQLEnumType.newEnum;
4950

5051
@Component(scope = ServiceScope.SINGLETON, property = "type=default")
@@ -226,7 +227,7 @@ private class EnumFunction implements TypeFunction {
226227
@Override
227228
public GraphQLType apply(Class<?> aClass, AnnotatedType annotatedType) {
228229
GraphQLName name = aClass.getAnnotation(GraphQLName.class);
229-
String typeName = name == null ? aClass.getSimpleName() : name.value();
230+
String typeName = toGraphqlName(name == null ? aClass.getSimpleName() : name.value());
230231

231232
if (types.containsKey(typeName)) {
232233
return types.get(typeName);
@@ -282,7 +283,7 @@ private class ObjectFunction implements TypeFunction {
282283
@Override
283284
public GraphQLType apply(Class<?> aClass, AnnotatedType annotatedType) {
284285
GraphQLName name = aClass.getAnnotation(GraphQLName.class);
285-
String typeName = name == null ? aClass.getName() : name.value();
286+
String typeName = toGraphqlName(name == null ? aClass.getName() : name.value());
286287
if (types.containsKey(typeName)) {
287288
return types.get(typeName);
288289
} else if (processing.containsKey(typeName)) {
@@ -293,7 +294,7 @@ public GraphQLType apply(Class<?> aClass, AnnotatedType annotatedType) {
293294
if (aClass.isInterface()) {
294295
type = annotationsProcessor.getInterface(aClass);
295296
} else {
296-
type = annotationsProcessor.getObject(aClass);
297+
type = annotationsProcessor.getObjectOrRef(aClass);
297298
}
298299
types.put(typeName, type);
299300
processing.remove(typeName);

src/main/java/graphql/annotations/EnhancedExecutionStrategy.java

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,27 +14,35 @@
1414
*/
1515
package graphql.annotations;
1616

17-
import graphql.ExceptionWhileDataFetching;
1817
import graphql.ExecutionResult;
1918
import graphql.execution.ExecutionContext;
19+
import graphql.execution.ExecutionParameters;
2020
import graphql.execution.SimpleExecutionStrategy;
21-
import graphql.language.*;
22-
import graphql.schema.*;
21+
import graphql.execution.TypeInfo;
22+
import graphql.language.Argument;
23+
import graphql.language.Field;
24+
import graphql.language.ObjectValue;
25+
import graphql.language.StringValue;
26+
import graphql.language.VariableReference;
27+
import graphql.schema.GraphQLEnumType;
28+
import graphql.schema.GraphQLFieldDefinition;
29+
import graphql.schema.GraphQLObjectType;
2330
import graphql.schema.GraphQLType;
24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
2631

2732
import java.util.HashMap;
2833
import java.util.List;
2934
import java.util.Optional;
3035

36+
import static graphql.execution.ExecutionParameters.newParameters;
37+
import static graphql.execution.TypeInfoWorkaround.newTypeInfo;
38+
3139
public class EnhancedExecutionStrategy extends SimpleExecutionStrategy {
3240

33-
private static final Logger log = LoggerFactory.getLogger(EnhancedExecutionStrategy.class);
3441
private static final String CLIENT_MUTATION_ID = "clientMutationId";
3542

3643
@Override
37-
protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, List<Field> fields) {
44+
protected ExecutionResult resolveField(ExecutionContext executionContext, ExecutionParameters parameters, List<Field> fields) {
45+
GraphQLObjectType parentType = (GraphQLObjectType) parameters.typeInfo().type();
3846
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
3947
if (fieldDef == null) return null;
4048

@@ -43,7 +51,7 @@ protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQ
4351
Argument argument = field.getArguments().get(0);
4452

4553
Object clientMutationId;
46-
if (argument.getValue() instanceof VariableReference) {
54+
if (argument.getValue() instanceof VariableReference) {
4755
VariableReference ref = (VariableReference) argument.getValue();
4856
HashMap mutationInputVariables = (HashMap) executionContext.getVariables().get(ref.getName());
4957
clientMutationId = mutationInputVariables.get(CLIENT_MUTATION_ID);
@@ -55,20 +63,45 @@ protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQ
5563
clientMutationId = clientMutationIdVal.getValue();
5664
}
5765

58-
return completeValue(executionContext, fieldDef.getType(), fields, clientMutationId);
66+
TypeInfo fieldTypeInfo = newTypeInfo(fieldDef.getType(), parameters.typeInfo());
67+
ExecutionParameters newParameters = newParameters()
68+
.arguments(parameters.arguments())
69+
.fields(parameters.fields())
70+
.typeInfo(fieldTypeInfo)
71+
.source(clientMutationId)
72+
.build();
73+
74+
75+
return completeValue(executionContext, newParameters, fields);
5976
} else {
60-
return super.resolveField(executionContext, parentType, source, fields);
77+
return super.resolveField(executionContext, parameters, fields);
6178
}
6279
}
6380

6481
@Override
65-
protected ExecutionResult completeValue(ExecutionContext executionContext, GraphQLType fieldType, List<Field> fields, Object result) {
82+
protected ExecutionResult completeValue(ExecutionContext executionContext, ExecutionParameters parameters, List<Field> fields) {
83+
GraphQLType fieldType = parameters.typeInfo().type();
84+
Object result = parameters.source();
6685
if (result instanceof Enum && fieldType instanceof GraphQLEnumType) {
67-
return super.completeValue(executionContext, fieldType, fields, ((GraphQLEnumType) fieldType).getCoercing().parseValue(((Enum) result).name()));
86+
Object value = ((GraphQLEnumType) fieldType).getCoercing().parseValue(((Enum) result).name());
87+
return super.completeValue(executionContext, withSource(parameters, value), fields);
6888
}
6989
if (result instanceof Optional) {
70-
return completeValue(executionContext, fieldType, fields, ((Optional) result).orElse(null));
90+
Object value = ((Optional<?>) result).orElse(null);
91+
return completeValue(executionContext, withSource(parameters, value), fields);
7192
}
72-
return super.completeValue(executionContext, fieldType, fields, result);
93+
return super.completeValue(executionContext, parameters, fields);
94+
}
95+
96+
/*
97+
Creates a new parameters with the specified object as its source
98+
*/
99+
private ExecutionParameters withSource(ExecutionParameters parameters, Object source) {
100+
return newParameters()
101+
.arguments(parameters.arguments())
102+
.fields(parameters.fields())
103+
.typeInfo(parameters.typeInfo())
104+
.source(source)
105+
.build();
73106
}
74107
}

0 commit comments

Comments
 (0)