Skip to content

Commit 2e2d6dc

Browse files
committed
fixing the issue with only enum tests failing
1 parent 99ff53c commit 2e2d6dc

File tree

9 files changed

+97
-43
lines changed

9 files changed

+97
-43
lines changed

src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLInputProcessor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717

1818
import graphql.annotations.processor.retrievers.GraphQLInputObjectRetriever;
19-
import graphql.annotations.processor.retrievers.GraphQLObjectHandler;
2019
import graphql.annotations.processor.ProcessingElementsContainer;
2120
import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever;
22-
import graphql.annotations.processor.retrievers.GraphQLOutputObjectRetriever;
21+
import graphql.annotations.processor.retrievers.GraphQLTypeRetriever;
2322
import graphql.schema.GraphQLInputObjectType;
2423
import graphql.schema.GraphQLInputType;
2524
import graphql.schema.GraphQLType;
@@ -31,17 +30,17 @@ public class GraphQLInputProcessor {
3130
private static final String DEFAULT_INPUT_PREFIX = "Input";
3231

3332
private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever;
34-
private GraphQLOutputObjectRetriever graphQLOutputObjectRetriever;
33+
private GraphQLTypeRetriever graphQLOutputObjectRetriever;
3534
private GraphQLInputObjectRetriever graphQLInputObjectRetriever;
3635

37-
public GraphQLInputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLOutputObjectRetriever graphQLOutputObjectRetriever, GraphQLInputObjectRetriever graphQLInputObjectRetriever) {
36+
public GraphQLInputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLTypeRetriever graphQLOutputObjectRetriever, GraphQLInputObjectRetriever graphQLInputObjectRetriever) {
3837
this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever;
3938
this.graphQLOutputObjectRetriever = graphQLOutputObjectRetriever;
4039
this.graphQLInputObjectRetriever = graphQLInputObjectRetriever;
4140
}
4241

4342
public GraphQLInputProcessor() {
44-
this(new GraphQLObjectInfoRetriever(), new GraphQLOutputObjectRetriever(), new GraphQLInputObjectRetriever());
43+
this(new GraphQLObjectInfoRetriever(), new GraphQLTypeRetriever(), new GraphQLInputObjectRetriever());
4544
}
4645

4746
/**
@@ -59,7 +58,7 @@ public GraphQLInputType getInputType(Class<?> object, ProcessingElementsContaine
5958
if (typeRegistry.containsKey(typeName)) {
6059
return (GraphQLInputObjectType) container.getTypeRegistry().get(typeName);
6160
} else {
62-
graphql.schema.GraphQLType graphQLType = graphQLOutputObjectRetriever.getOutputType(object, container);
61+
graphql.schema.GraphQLType graphQLType = graphQLOutputObjectRetriever.getGraphQLType(object, container, true);
6362
GraphQLInputType inputObject = graphQLInputObjectRetriever.getInputObject(graphQLType, DEFAULT_INPUT_PREFIX, typeRegistry);
6463
typeRegistry.put(inputObject.getName(), inputObject);
6564
return inputObject;

src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLOutputProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@
1818
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
1919
import graphql.annotations.processor.ProcessingElementsContainer;
2020
import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever;
21-
import graphql.annotations.processor.retrievers.GraphQLOutputObjectRetriever;
21+
import graphql.annotations.processor.retrievers.GraphQLTypeRetriever;
2222
import graphql.schema.GraphQLOutputType;
2323
import graphql.schema.GraphQLTypeReference;
2424

2525
public class GraphQLOutputProcessor {
2626

2727
private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever;
28-
private GraphQLOutputObjectRetriever outputObjectRetriever;
28+
private GraphQLTypeRetriever outputObjectRetriever;
2929

3030

31-
public GraphQLOutputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLOutputObjectRetriever outputObjectRetriever) {
31+
public GraphQLOutputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLTypeRetriever outputObjectRetriever) {
3232
this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever;
3333
this.outputObjectRetriever = outputObjectRetriever;
3434
}
3535

3636
public GraphQLOutputProcessor() {
37-
this(new GraphQLObjectInfoRetriever(), new GraphQLOutputObjectRetriever());
37+
this(new GraphQLObjectInfoRetriever(), new GraphQLTypeRetriever());
3838
}
3939

4040
/**
@@ -55,7 +55,7 @@ public GraphQLOutputType getOutputTypeOrRef(Class<?> object, ProcessingElementsC
5555
return new GraphQLTypeReference(typeName);
5656
}
5757

58-
return outputObjectRetriever.getOutputType(object, container);
58+
return (GraphQLOutputType) outputObjectRetriever.getGraphQLType(object, container, false);
5959
}
6060

6161
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class GraphQLInputObjectRetriever {
3535
*/
3636

3737
public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, String newNamePrefix, Map<String, graphql.schema.GraphQLType> typeRegistry) {
38+
3839
if (graphQLType instanceof GraphQLObjectType) {
3940
return handleGraphQLObjectType((GraphQLObjectType) graphQLType, newNamePrefix, typeRegistry);
4041
} else if (graphQLType instanceof GraphQLList) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
import graphql.annotations.processor.ProcessingElementsContainer;
1919
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
20+
import graphql.schema.GraphQLOutputType;
2021

2122
public class GraphQLInterfaceRetriever {
2223

23-
private GraphQLOutputObjectRetriever graphQLOutputObjectRetriever;
24+
private GraphQLTypeRetriever graphQLOutputObjectRetriever;
2425

25-
public GraphQLInterfaceRetriever(GraphQLOutputObjectRetriever graphQLOutputObjectRetriever) {
26+
public GraphQLInterfaceRetriever(GraphQLTypeRetriever graphQLOutputObjectRetriever) {
2627
this.graphQLOutputObjectRetriever = graphQLOutputObjectRetriever;
2728
}
2829

2930
public GraphQLInterfaceRetriever() {
30-
this(new GraphQLOutputObjectRetriever());
31+
this(new GraphQLTypeRetriever());
3132
}
3233

3334
/**
@@ -39,6 +40,6 @@ public GraphQLInterfaceRetriever() {
3940
* @throws GraphQLAnnotationsException if the class cannot be examined
4041
*/
4142
public graphql.schema.GraphQLOutputType getInterface(Class<?> iface, ProcessingElementsContainer container) throws GraphQLAnnotationsException {
42-
return graphQLOutputObjectRetriever.getOutputType(iface, container);
43+
return (GraphQLOutputType) graphQLOutputObjectRetriever.getGraphQLType(iface, container, false);
4344
}
4445
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222

2323
public class GraphQLObjectHandler {
2424

25-
private GraphQLOutputObjectRetriever outputObjectRetriever;
25+
private GraphQLTypeRetriever outputObjectRetriever;
2626

27-
public GraphQLObjectHandler(GraphQLOutputObjectRetriever outputObjectRetriever) {
27+
public GraphQLObjectHandler(GraphQLTypeRetriever outputObjectRetriever) {
2828
this.outputObjectRetriever = outputObjectRetriever;
2929
}
3030

3131
public GraphQLObjectHandler() {
32-
this(new GraphQLOutputObjectRetriever());
32+
this(new GraphQLTypeRetriever());
3333
}
3434

3535
public GraphQLObjectType getObject(Class<?> object, ProcessingElementsContainer container) throws GraphQLAnnotationsException, CannotCastMemberException {
36-
GraphQLOutputType type = outputObjectRetriever.getOutputType(object, container);
36+
GraphQLOutputType type = (GraphQLOutputType) outputObjectRetriever.getGraphQLType(object, container, false);
3737
if (type instanceof GraphQLObjectType) {
3838
return (GraphQLObjectType) type;
3939
} else {

src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java renamed to src/main/java/graphql/annotations/processor/retrievers/GraphQLTypeRetriever.java

Lines changed: 21 additions & 14 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.
@@ -27,43 +27,49 @@
2727
import graphql.annotations.processor.typeBuilders.UnionBuilder;
2828
import graphql.schema.*;
2929

30-
public class GraphQLOutputObjectRetriever {
30+
public class GraphQLTypeRetriever {
3131

3232
private GraphQLObjectInfoRetriever graphQLObjectInfoRetriever;
3333
private GraphQLFieldRetriever graphQLFieldRetriever;
3434

35-
public GraphQLOutputObjectRetriever(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLFieldRetriever graphQLFieldRetriever) {
35+
public GraphQLTypeRetriever(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLFieldRetriever graphQLFieldRetriever) {
3636
this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever;
3737
this.graphQLFieldRetriever = graphQLFieldRetriever;
3838
}
3939

40-
public GraphQLOutputObjectRetriever() {
40+
public GraphQLTypeRetriever() {
4141
this(new GraphQLObjectInfoRetriever(), new GraphQLFieldRetriever());
4242
}
4343

4444
/**
45-
* This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotationTypes.
45+
* This will examine the object and will return a {@link GraphQLType} based on the class type and annotationTypes.
4646
* - If its annotated with {@link graphql.annotations.annotationTypes.GraphQLUnion} it will return a {@link GraphQLUnionType}
4747
* - If its annotated with {@link graphql.annotations.annotationTypes.GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType}
4848
* - It it's an Enum it will return a {@link GraphQLEnumType},
4949
* otherwise it will return a {@link GraphQLObjectType}.
5050
*
5151
* @param object the object class to examine*
5252
* @param container a class that hold several members that are required in order to build schema
53-
* @return a {@link GraphQLOutputType} that represents that object class
53+
* @return a {@link GraphQLType} that represents that object class
5454
* @throws graphql.annotations.processor.exceptions.GraphQLAnnotationsException if the object class cannot be examined
5555
* @throws graphql.annotations.processor.exceptions.CannotCastMemberException if the object class cannot be examined
5656
*/
57-
public GraphQLOutputType getOutputType(Class<?> object, ProcessingElementsContainer container) throws GraphQLAnnotationsException, CannotCastMemberException {
57+
public GraphQLType getGraphQLType(Class<?> object, ProcessingElementsContainer container, boolean isInputHirerarchy) throws GraphQLAnnotationsException, CannotCastMemberException {
5858
// because the TypeFunction can call back to this processor and
5959
// Java classes can be circular, we need to protect against
6060
// building the same type twice because graphql-java 3.x requires
6161
// all type instances to be unique singletons
6262
String typeName = graphQLObjectInfoRetriever.getTypeName(object);
63-
64-
GraphQLOutputType type = (GraphQLOutputType) container.getTypeRegistry().get(typeName);
65-
if (type != null) { // type already exists, do not build a new new one
66-
return type;
63+
GraphQLType type;
64+
if (isInputHirerarchy) {
65+
String typeNameWithPrefix = "Input" + typeName;
66+
type = container.getTypeRegistry().get(typeNameWithPrefix);
67+
if (type != null) return type;
68+
} else {
69+
type = container.getTypeRegistry().get(typeName);
70+
if (type != null) { // type already exists, do not build a new new one
71+
return type;
72+
}
6773
}
6874

6975
container.getProcessing().push(typeName);
@@ -77,6 +83,7 @@ public GraphQLOutputType getOutputType(Class<?> object, ProcessingElementsContai
7783
type = new ObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), graphQLFieldRetriever, new GraphQLInterfaceRetriever()).getObjectBuilder(object, container).build();
7884
}
7985

86+
if (isInputHirerarchy) typeName = "Input" + typeName;
8087
container.getTypeRegistry().put(typeName, type);
8188
container.getProcessing().pop();
8289

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public List<GraphQLArgument> build() {
6161
filter(p -> !DataFetchingEnvironment.class.isAssignableFrom(p.getType())).
6262
map(parameter -> {
6363
Class<?> t = parameter.getType();
64-
graphql.schema.GraphQLInputType graphQLType = graphQLInputObjectRetriever.getInputObject(finalTypeFunction.buildType(true, t, parameter.getAnnotatedType(), container), DEFAULT_INPUT_PREFIX, container.getTypeRegistry());
64+
graphql.schema.GraphQLInputType graphQLType = graphQLInputObjectRetriever.getInputObject(finalTypeFunction.buildType(true, t, parameter.getAnnotatedType(), container)
65+
, DEFAULT_INPUT_PREFIX, container.getTypeRegistry());
6566
return getArgument(parameter, graphQLType);
6667
}).collect(Collectors.toList());
6768

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

Lines changed: 50 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-
*
7+
* <p>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
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.
@@ -108,7 +108,7 @@ public String value(@GraphQLName("input") List<List<List<InputObject>>> input) {
108108
public static class TestObjectRec {
109109
@GraphQLField
110110
public String value(@GraphQLName("input") RecursiveInputObject input) {
111-
return (input.rec != null ? ("rec"+input.rec.key) : input.key) + "a";
111+
return (input.rec != null ? ("rec" + input.rec.key) : input.key) + "a";
112112
}
113113
}
114114

@@ -140,21 +140,27 @@ public static class Query {
140140
@GraphQLField
141141
public TestIface object() {
142142
return new TestObject();
143-
};
143+
}
144+
145+
;
144146
}
145147

146148
public static class QueryRecursion {
147149
@GraphQLField
148150
public TestObjectRec object() {
149151
return new TestObjectRec();
150-
};
152+
}
153+
154+
;
151155
}
152156

153157
public static class QueryList {
154158
@GraphQLField
155159
public TestObjectList object() {
156160
return new TestObjectList();
157-
};
161+
}
162+
163+
;
158164
}
159165

160166
public static class QueryIface {
@@ -219,5 +225,42 @@ public void queryWithInterface() {
219225
assertEquals(((Map<String, Map<String, String>>) result.getData()).get("iface").get("value"), "testa");
220226
}
221227

228+
@GraphQLName("hero")
229+
public class Hero {
230+
@GraphQLField
231+
int a;
232+
}
233+
234+
@GraphQLName("hero")
235+
public class HeroInput {
236+
@GraphQLField
237+
String b;
238+
239+
@GraphQLField
240+
Skill skill;
241+
}
242+
243+
public class Skill{
244+
@GraphQLField
245+
String c;
246+
}
247+
248+
public class QueryInputAndOutput {
249+
@GraphQLField
250+
public Hero getHero() {
251+
return null;
252+
}
253+
254+
@GraphQLField
255+
public String getString(HeroInput input) {
256+
return "asdf";
257+
}
258+
}
259+
260+
@Test
261+
public void testInputAndOutputWithSameName() {
262+
GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(QueryInputAndOutput.class)).build();
263+
int x =5;
264+
}
222265

223266
}

src/test/java/graphql/annotations/GraphQLObjectTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ public void complexInputObjectArgument() {
667667
public void inputObject() {
668668
GraphQLObjectType object = GraphQLAnnotations.object(TestObjectInput.class);
669669
GraphQLInputObjectRetriever graphQLInputObjectRetrieve=new GraphQLInputObjectRetriever();
670-
GraphQLInputObjectType inputObjectType = (GraphQLInputObjectType) graphQLInputObjectRetrieve.getInputObject(object, "input",GraphQLAnnotations.getInstance().getContainer().getTypeRegistry());
670+
GraphQLInputObjectType inputObjectType = (GraphQLInputObjectType) graphQLInputObjectRetrieve.getInputObject(object, "input",
671+
GraphQLAnnotations.getInstance().getContainer().getTypeRegistry());
671672
assertEquals(inputObjectType.getFields().size(), object.getFieldDefinitions().size());
672673
}
673674

@@ -732,7 +733,8 @@ public void queryOptional() {
732733
public void optionalInput() {
733734
GraphQLObjectType object = GraphQLAnnotations.object(OptionalTest.class);
734735
GraphQLInputObjectRetriever graphQLInputObjectRetriever=new GraphQLInputObjectRetriever();
735-
GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(object, "input",GraphQLAnnotations.getInstance().getTypeRegistry());
736+
GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(object, "input",
737+
GraphQLAnnotations.getInstance().getTypeRegistry());
736738
GraphQLObjectType mutation = GraphQLObjectType.newObject().name("mut").field(newFieldDefinition().name("test").type(object).
737739
argument(GraphQLArgument.newArgument().type(inputObject).name("input").build()).dataFetcher(environment -> {
738740
Map<String, String> input = environment.getArgument("input");

0 commit comments

Comments
 (0)