Skip to content

Commit d2af000

Browse files
committed
feature: update to gql-java-14
1 parent 0ab3ace commit d2af000

File tree

9 files changed

+82
-57
lines changed

9 files changed

+82
-57
lines changed

build.gradle

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

6464
dependencies {
6565
compile 'javax.validation:validation-api:1.1.0.Final'
66-
compile 'com.graphql-java:graphql-java:13.0'
66+
compile 'com.graphql-java:graphql-java:14.0'
6767

6868
// OSGi
6969
compileOnly 'org.osgi:org.osgi.core:6.0.0'

src/main/java/graphql/annotations/processor/retrievers/GraphQLFieldRetriever.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,6 +49,7 @@
4949
import java.util.Map;
5050
import java.util.stream.Collectors;
5151

52+
import static graphql.annotations.processor.util.GraphQLTypeNameResolver.getName;
5253
import static graphql.annotations.processor.util.ReflectionKit.newInstance;
5354
import static graphql.schema.FieldCoordinates.coordinates;
5455
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
@@ -154,10 +155,10 @@ private GraphQLFieldDefinition handleRelayArguments(Method method, ProcessingEle
154155
relayFieldDefinition = buildRelayMutation(method, container, builder, outputType, args);
155156

156157
// Getting the data fetcher from the old field type and putting it as the new type
157-
String newParentType = relayFieldDefinition.getType().getName();
158+
String newParentType = (getName(relayFieldDefinition.getType()));
158159
relayFieldDefinition.getType().getChildren().forEach(field -> {
159-
DataFetcher dataFetcher = CodeRegistryUtil.getDataFetcher(container.getCodeRegistryBuilder(), outputType.getName(), (GraphQLFieldDefinition) field);
160-
container.getCodeRegistryBuilder().dataFetcher(coordinates(newParentType, field.getName()), dataFetcher);
160+
DataFetcher dataFetcher = CodeRegistryUtil.getDataFetcher(container.getCodeRegistryBuilder(), getName(outputType), (GraphQLFieldDefinition) field);
161+
container.getCodeRegistryBuilder().dataFetcher(coordinates(newParentType, getName(field)), dataFetcher);
161162
});
162163

163164
} else {
@@ -217,10 +218,10 @@ private GraphQLOutputType getGraphQLConnection(AccessibleObject field, graphql.s
217218
}
218219

219220
private GraphQLOutputType internalGetGraphQLConnection(AccessibleObject field, GraphQLList listType, Relay relay, Map<String, graphql.schema.GraphQLType> typeRegistry) {
220-
GraphQLOutputType wrappedType = (GraphQLOutputType) listType.getWrappedType();
221+
GraphQLType wrappedType = listType.getWrappedType();
221222
String connectionName = field.getAnnotation(GraphQLConnection.class).name();
222-
connectionName = connectionName.isEmpty() ? wrappedType.getName() : connectionName;
223-
GraphQLObjectType edgeType = getActualType(relay.edgeType(connectionName, wrappedType, null, Collections.emptyList()), typeRegistry);
223+
connectionName = connectionName.isEmpty() ? getName(wrappedType) : connectionName;
224+
GraphQLObjectType edgeType = getActualType(relay.edgeType(connectionName, (GraphQLOutputType) wrappedType, null, Collections.emptyList()), typeRegistry);
224225
return getActualType(relay.connectionType(connectionName, edgeType, Collections.emptyList()), typeRegistry);
225226
}
226227

src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,6 +23,7 @@
2323
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
2424
import graphql.annotations.processor.searchAlgorithms.SearchAlgorithm;
2525
import graphql.annotations.processor.typeBuilders.*;
26+
import graphql.annotations.processor.util.GraphQLTypeNameResolver;
2627
import graphql.schema.*;
2728
import org.osgi.service.component.annotations.*;
2829

@@ -90,11 +91,11 @@ public GraphQLType getGraphQLType(Class<?> object, ProcessingElementsContainer c
9091
DirectiveWirer directiveWirer = new DirectiveWirer();
9192

9293
// wire the type with the directives and change the original type
93-
type = directiveWirer.wire((GraphQLDirectiveContainer) type,
94+
type = (GraphQLType) directiveWirer.wire((GraphQLDirectiveContainer) type,
9495
new DirectiveWiringMapRetriever().getDirectiveWiringMap(object, container),
9596
container.getCodeRegistryBuilder(), null);
9697

97-
container.getTypeRegistry().put(type.getName(), type);
98+
container.getTypeRegistry().put(GraphQLTypeNameResolver.getName(type), type);
9899
container.getProcessing().pop();
99100

100101
return type;

src/main/java/graphql/annotations/processor/retrievers/fieldBuilders/ArgumentBuilder.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,16 +17,19 @@
1717
import graphql.annotations.annotationTypes.GraphQLDefaultValue;
1818
import graphql.annotations.annotationTypes.GraphQLDescription;
1919
import graphql.annotations.annotationTypes.GraphQLName;
20+
import graphql.annotations.directives.AnnotationsDirectiveWiring;
2021
import graphql.annotations.directives.DirectiveWirer;
2122
import graphql.annotations.directives.DirectiveWiringMapRetriever;
2223
import graphql.annotations.processor.ProcessingElementsContainer;
2324
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
2425
import graphql.annotations.processor.typeFunctions.TypeFunction;
26+
import graphql.annotations.processor.util.GraphQLTypeNameResolver;
2527
import graphql.schema.*;
2628

2729
import java.lang.reflect.Method;
2830
import java.lang.reflect.Parameter;
2931
import java.util.Arrays;
32+
import java.util.HashMap;
3033
import java.util.List;
3134
import java.util.stream.Collectors;
3235

@@ -81,9 +84,11 @@ private GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLI
8184
argumentBuilder.name(toGraphqlName(parameter.getName()));
8285
}
8386
argumentBuilder.withDirectives(new DirectivesBuilder(parameter, container).build());
84-
return (GraphQLArgument) new DirectiveWirer().wire(argumentBuilder.build(),
85-
new DirectiveWiringMapRetriever().getDirectiveWiringMap(parameter, container), container.getCodeRegistryBuilder(),
86-
inputType.getName());
87+
GraphQLArgument builtArgument = argumentBuilder.build();
88+
HashMap<GraphQLDirective, AnnotationsDirectiveWiring> directiveWiringMap = new DirectiveWiringMapRetriever().getDirectiveWiringMap(parameter, container);
89+
return (GraphQLArgument) new DirectiveWirer().wire(builtArgument,
90+
directiveWiringMap, container.getCodeRegistryBuilder(),
91+
GraphQLTypeNameResolver.getName(inputType));
8792
}
8893

8994
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package graphql.annotations.processor.util;
2+
3+
import graphql.schema.*;
4+
5+
public class GraphQLTypeNameResolver {
6+
public static String getName(GraphQLSchemaElement graphQLSchemaElement) {
7+
try {
8+
return ((GraphQLNamedSchemaElement) graphQLSchemaElement).getName();
9+
} catch (Exception exception) {
10+
if (graphQLSchemaElement instanceof GraphQLNonNull) {
11+
return getName(((GraphQLNonNull) graphQLSchemaElement).getWrappedType());
12+
} else if (graphQLSchemaElement instanceof GraphQLList) {
13+
GraphQLType iterator = (GraphQLType) graphQLSchemaElement;
14+
do {
15+
iterator = ((GraphQLList) iterator).getWrappedType();
16+
} while (iterator instanceof GraphQLList);
17+
return getName(iterator);
18+
} else {
19+
throw new RuntimeException("Cannot determine name for schema element");
20+
}
21+
}
22+
}
23+
}

src/test/java/graphql/annotations/GraphQLInputTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,10 +22,7 @@
2222
import graphql.annotations.annotationTypes.GraphQLTypeResolver;
2323
import graphql.annotations.processor.GraphQLAnnotations;
2424
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
25-
import graphql.schema.GraphQLInputObjectType;
26-
import graphql.schema.GraphQLObjectType;
27-
import graphql.schema.GraphQLSchema;
28-
import graphql.schema.TypeResolver;
25+
import graphql.schema.*;
2926
import org.testng.annotations.BeforeMethod;
3027
import org.testng.annotations.Test;
3128

@@ -297,19 +294,19 @@ public void testInputAndOutputWithSameName() {
297294
// arrange + act
298295
GraphQLSchema schema = newSchema().query(this.graphQLAnnotations.object(QueryInputAndOutput.class)).build();
299296
// assert
300-
assertEquals(schema.getQueryType().getFieldDefinition("getHero").getType().getName(), "hero");
301-
assertEquals(schema.getQueryType().getFieldDefinition("getString").getArgument("input").getType().getName(), "Inputhero");
302-
assertEquals(((GraphQLInputObjectType) schema.getQueryType().getFieldDefinition("getString")
303-
.getArgument("input").getType()).getField("skill").getType().getName(), "InputSkill");
297+
assertEquals(((GraphQLNamedType) (schema.getQueryType().getFieldDefinition("getHero").getType())).getName(), "hero");
298+
assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getString").getArgument("input").getType()).getName(), "Inputhero");
299+
assertEquals(((GraphQLNamedType) ((GraphQLInputObjectType) schema.getQueryType().getFieldDefinition("getString")
300+
.getArgument("input").getType()).getField("skill").getType()).getName(), "InputSkill");
304301
}
305302

306303
@Test
307304
public void testInputAndOutputSameClass() {
308305
// arrange + act
309306
GraphQLSchema schema = newSchema().query(this.graphQLAnnotations.object(QueryInputAndOutput2.class)).build();
310307
// assert
311-
assertEquals(schema.getQueryType().getFieldDefinition("getSkill").getType().getName(), "Skill");
312-
assertEquals(schema.getQueryType().getFieldDefinition("getA").getArgument("skill").getType().getName(), "InputSkill");
308+
assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getSkill").getType()).getName(), "Skill");
309+
assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getA").getArgument("skill").getType()).getName(), "InputSkill");
313310
}
314311

315312
@GraphQLName("A")
@@ -366,11 +363,11 @@ public void testInputAndOutputWithSameNameWithChildrenWithSameName() {
366363
// arrange + act
367364
GraphQLSchema schema = newSchema().query(this.graphQLAnnotations.object(QuerySameNameWithChildren.class)).build();
368365
// assert
369-
assertEquals(schema.getQueryType().getFieldDefinition("getAout").getType().getName(), "A");
370-
assertEquals(schema.getQueryType().getFieldDefinition("getAout").getType().getClass(), GraphQLObjectType.class);
371-
assertEquals(schema.getQueryType().getFieldDefinition("getBout").getType().getName(), "B");
366+
assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getAout").getType()).getName(), "A");
367+
assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getAout").getType()).getClass(), GraphQLObjectType.class);
368+
assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getBout").getType()).getName(), "B");
372369
assertEquals(schema.getQueryType().getFieldDefinition("getBout").getType().getClass(), GraphQLObjectType.class);
373-
assertEquals(schema.getQueryType().getFieldDefinition("getA").getArgument("input").getType().getName(), "InputA");
370+
assertEquals(((GraphQLNamedType) schema.getQueryType().getFieldDefinition("getA").getArgument("input").getType()).getName(), "InputA");
374371
assertEquals(schema.getQueryType().getFieldDefinition("getA").getArgument("input").getType().getClass(), GraphQLInputObjectType.class);
375372
assertEquals(schema.getQueryType().getFieldDefinition("getB").getArgument("input").getType().getClass(), GraphQLInputObjectType.class);
376373

src/test/java/graphql/annotations/GraphQLInterfaceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -129,7 +129,7 @@ public void testUnion() {
129129
@Test
130130
public void testInterfaces() {
131131
GraphQLObjectType object = this.graphQLAnnotations.object(TestObject.class);
132-
List<GraphQLOutputType> ifaces = object.getInterfaces();
132+
List<GraphQLNamedOutputType> ifaces = object.getInterfaces();
133133
assertEquals(ifaces.size(), 1);
134134
assertEquals(ifaces.get(0).getName(), "TestIface");
135135
}

src/test/java/graphql/annotations/connection/GraphQLConnectionTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Yurii Rashkovskii
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,10 +24,7 @@
2424
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
2525
import graphql.annotations.processor.util.CustomRelay;
2626
import graphql.relay.Relay;
27-
import graphql.schema.DataFetchingEnvironment;
28-
import graphql.schema.GraphQLList;
29-
import graphql.schema.GraphQLObjectType;
30-
import graphql.schema.GraphQLSchema;
27+
import graphql.schema.*;
3128
import org.testng.annotations.BeforeMethod;
3229
import org.testng.annotations.Test;
3330

@@ -162,7 +159,7 @@ public void customRelayMethodList() {
162159
graphql.schema.GraphQLObjectType f = (GraphQLObjectType) schema.getType("ObjConnection");
163160
assertTrue(f.getFieldDefinitions().size() == 4);
164161
assertTrue(f.getFieldDefinition("nodes").getType() instanceof GraphQLList);
165-
assertEquals(((GraphQLList) f.getFieldDefinition("nodes").getType()).getWrappedType().getName(), "Obj");
162+
assertEquals(((GraphQLNamedType) ((GraphQLList) f.getFieldDefinition("nodes").getType()).getWrappedType()).getName(), "Obj");
166163

167164
GraphQLObjectType pageInfo = (GraphQLObjectType) schema.getType("PageInfo");
168165
assertTrue(pageInfo.getFieldDefinition("additionalInfo") != null);

src/test/java/graphql/annotations/connection/GraphQLSimpleConnectionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import graphql.annotations.processor.GraphQLAnnotations;
2424
import graphql.schema.DataFetcher;
2525
import graphql.schema.DataFetchingEnvironment;
26+
import graphql.schema.GraphQLNamedType;
2627
import graphql.schema.GraphQLSchema;
2728
import org.testng.annotations.BeforeMethod;
2829
import org.testng.annotations.Test;
@@ -50,7 +51,7 @@ public void init() {
5051
public void simpleConnection_buildSchema_TypeOfSimpleConnectionIsGraphQLList() throws Exception {
5152
GraphQLSchema schema = newAnnotationsSchema().query(MainConnection.class).build();
5253

53-
String objsTypeName = schema.getQueryType().getFieldDefinition("objs").getType().getName();
54+
String objsTypeName = ((GraphQLNamedType)schema.getQueryType().getFieldDefinition("objs").getType()).getName();
5455

5556
assertThat(objsTypeName, is("ObjChunk"));
5657
}

0 commit comments

Comments
 (0)