Skip to content

Commit 25dc14b

Browse files
committed
Merge remote-tracking branch 'imri/refactor-DefaultTypeFunction' into refactoring
# Conflicts: # src/main/java/graphql/annotations/processor/graphQLProcessors/GraphQLAnnotationsProcessor.java # src/main/java/graphql/annotations/processor/retrievers/GraphQLInterfaceRetriever.java # src/main/java/graphql/annotations/processor/retrievers/GraphQLOutputObjectRetriever.java
2 parents f05ca9f + 156d8ad commit 25dc14b

File tree

9 files changed

+117
-156
lines changed

9 files changed

+117
-156
lines changed

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

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -12,120 +12,9 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
*/
15-
package graphql.annotations.processor.graphQLProcessors;
16-
17-
import graphql.annotations.annotations.GraphQLTypeExtension;
15+
package graphql.annotations;
1816

1917
public interface GraphQLAnnotationsProcessor {
20-
// /**
21-
// * @deprecated See {@link #getOutputType(Class)}
22-
// */
23-
// graphql.schema.GraphQLType getInterface(Class<?> iface) throws GraphQLAnnotationsException;
24-
//
25-
// /**
26-
// * This will examine the class and return a {@link GraphQLUnionType.Builder} ready for further definition
27-
// *
28-
// * @param iface interface to examine
29-
// *
30-
// * @return a {@link GraphQLUnionType.Builder}
31-
// *
32-
// * @throws GraphQLAnnotationsException if the class cannot be examined
33-
// * @throws IllegalArgumentException if <code>iface</code> is not an interface
34-
// */
35-
// GraphQLUnionType.Builder getUnionBuilder(Class<?> iface) throws GraphQLAnnotationsException, IllegalArgumentException;
36-
//
37-
// /**
38-
// * This will examine the class and return a {@link GraphQLInterfaceType.Builder} ready for further definition
39-
// *
40-
// * @param iface interface to examine
41-
// *
42-
// * @return a {@link GraphQLInterfaceType.Builder}
43-
// *
44-
// * @throws GraphQLAnnotationsException if the class cannot be examined
45-
// * @throws IllegalArgumentException if <code>iface</code> is not an interface
46-
// */
47-
// GraphQLInterfaceType.Builder getIfaceBuilder(Class<?> iface) throws GraphQLAnnotationsException, IllegalArgumentException;
48-
//
49-
// /**
50-
// * This will examine the object class and return a {@link GraphQLEnumType.Builder} ready for further definition
51-
// *
52-
// * @param object the object class to examine
53-
// *
54-
// * @return a {@link GraphQLEnumType.Builder} that represents that object class
55-
// *
56-
// * @throws GraphQLAnnotationsException if the object class cannot be examined
57-
// */
58-
// GraphQLEnumType.Builder getEnumBuilder(Class<?> object) throws GraphQLAnnotationsException;
59-
//
60-
// /**
61-
// * @deprecated See {@link #getOutputType(Class)}
62-
// */
63-
// GraphQLObjectType getObject(Class<?> object) throws GraphQLAnnotationsException;
64-
//
65-
// /**
66-
// * This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotations.
67-
// * - If its annotated with {@link GraphQLUnion} it will return a {@link GraphQLUnionType}
68-
// * - If its annotated with {@link GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType}
69-
// * - It it's an Enum it will return a {@link GraphQLEnumType},
70-
// * otherwise it will return a {@link GraphQLObjectType}.
71-
// *
72-
// * @param object the object class to examine
73-
// *
74-
// * @return a {@link GraphQLOutputType} that represents that object class
75-
// *
76-
// * @throws GraphQLAnnotationsException if the object class cannot be examined
77-
// */
78-
// GraphQLOutputType getOutputType(Class<?> object) throws GraphQLAnnotationsException;
79-
//
80-
// /**
81-
// * @deprecated See {@link #getOutputTypeOrRef(Class)}
82-
// */
83-
// GraphQLOutputType getObjectOrRef(Class<?> object) throws GraphQLAnnotationsException;
84-
//
85-
// /**
86-
// * This will examine the object class and return a {@link GraphQLOutputType} representation
87-
// * which may be a {@link GraphQLOutputType} or a {@link graphql.schema.GraphQLTypeReference}
88-
// *
89-
// * @param object the object class to examine
90-
// *
91-
// * @return a {@link GraphQLOutputType} that represents that object class
92-
// *
93-
// * @throws GraphQLAnnotationsException if the object class cannot be examined
94-
// */
95-
// GraphQLOutputType getOutputTypeOrRef(Class<?> object) throws GraphQLAnnotationsException;
96-
//
97-
// /**
98-
// * This will examine the object class and return a {@link GraphQLObjectType.Builder} ready for further definition
99-
// *
100-
// * @param object the object class to examine
101-
// *
102-
// * @return a {@link GraphQLObjectType.Builder} that represents that object class
103-
// *
104-
// * @throws GraphQLAnnotationsException if the object class cannot be examined
105-
// */
106-
// GraphQLObjectType.Builder getObjectBuilder(Class<?> object) throws GraphQLAnnotationsException;
107-
//
108-
// /**
109-
// * This will examine the object class and return a {@link GraphQLInputType} representation
110-
// *
111-
// * @param object the object class to examine
112-
// *
113-
// * @return a {@link GraphQLInputType} that represents that object class
114-
// *
115-
// * @throws GraphQLAnnotationsException if the object class cannot be examined
116-
// */
117-
// GraphQLInputObjectType getInputObject(Class<?> object) throws GraphQLAnnotationsException;
118-
//
119-
// /**
120-
// * This will turn a {@link GraphQLObjectType} into a corresponding {@link GraphQLInputObjectType}
121-
// *
122-
// * @param graphQLType the graphql object type
123-
// * @param newNamePrefix since graphql types MUST be unique, this prefix will be applied to the new input types
124-
// *
125-
// * @return a {@link GraphQLInputObjectType}
126-
// */
127-
// GraphQLInputType getInputObject(GraphQLType graphQLType, String newNamePrefix);
128-
12918
/**
13019
* Register a new type extension class. This extension will be used when the extended object will be created.
13120
* The class must have a {@link GraphQLTypeExtension} annotation.

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import graphql.annotations.processor.ProcessingElementsContainer;
2121
import graphql.annotations.processor.retrievers.GraphQLObjectInfoRetriever;
2222
import graphql.schema.GraphQLInputObjectType;
23+
import graphql.schema.GraphQLInputType;
2324
import graphql.schema.GraphQLType;
2425

2526
import java.util.Map;
@@ -32,24 +33,33 @@ public class GraphQLInputProcessor {
3233
private GraphQLObjectHandler graphQLObjectHandler;
3334
private GraphQLInputObjectRetriever graphQLInputObjectRetriever;
3435

35-
public GraphQLInputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever,GraphQLObjectHandler graphQLObjectHandler,GraphQLInputObjectRetriever graphQLInputObjectRetriever){
36-
this.graphQLObjectInfoRetriever=graphQLObjectInfoRetriever;
37-
this.graphQLObjectHandler=graphQLObjectHandler;
38-
this.graphQLInputObjectRetriever=graphQLInputObjectRetriever;
36+
public GraphQLInputProcessor(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever, GraphQLObjectHandler graphQLObjectHandler, GraphQLInputObjectRetriever graphQLInputObjectRetriever) {
37+
this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever;
38+
this.graphQLObjectHandler = graphQLObjectHandler;
39+
this.graphQLInputObjectRetriever = graphQLInputObjectRetriever;
3940
}
4041

41-
public GraphQLInputProcessor(){
42-
this(new GraphQLObjectInfoRetriever(), new GraphQLObjectHandler(),new GraphQLInputObjectRetriever());
42+
public GraphQLInputProcessor() {
43+
this(new GraphQLObjectInfoRetriever(), new GraphQLObjectHandler(), new GraphQLInputObjectRetriever());
4344
}
45+
46+
/**
47+
* This will examine the object class and return a {@link GraphQLInputType} representation
48+
*
49+
* @param object the object class to examine
50+
* @param container a class that hold several members that are required in order to build schema
51+
* @return a {@link GraphQLInputType} that represents that object class
52+
*/
53+
4454
public GraphQLInputObjectType getInputObject(Class<?> object, ProcessingElementsContainer container) {
4555
String typeName = DEFAULT_INPUT_PREFIX + graphQLObjectInfoRetriever.getTypeName(object);
4656
Map<String, GraphQLType> typeRegistry = container.getTypeRegistry();
4757

4858
if (typeRegistry.containsKey(typeName)) {
4959
return (GraphQLInputObjectType) container.getTypeRegistry().get(typeName);
5060
} else {
51-
graphql.schema.GraphQLType graphQLType = graphQLObjectHandler.getObject(object,container);
52-
GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(graphQLType, DEFAULT_INPUT_PREFIX,typeRegistry);
61+
graphql.schema.GraphQLType graphQLType = graphQLObjectHandler.getObject(object, container);
62+
GraphQLInputObjectType inputObject = (GraphQLInputObjectType) graphQLInputObjectRetriever.getInputObject(graphQLType, DEFAULT_INPUT_PREFIX, typeRegistry);
5363
typeRegistry.put(inputObject.getName(), inputObject);
5464
return inputObject;
5565
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public GraphQLOutputProcessor() {
3737
this(new GraphQLObjectInfoRetriever(), new GraphQLOutputObjectRetriever());
3838
}
3939

40+
/**
41+
* This will examine the object class and return a {@link GraphQLOutputType} representation
42+
* which may be a {@link GraphQLOutputType} or a {@link graphql.schema.GraphQLTypeReference}
43+
*
44+
* @param object the object class to examine
45+
* @param container a class that hold several members that are required in order to build schema
46+
47+
* @return a {@link GraphQLOutputType} that represents that object class
48+
*
49+
* @throws GraphQLAnnotationsException if the object class cannot be examined
50+
*/
51+
4052
public GraphQLOutputType getOutputTypeOrRef(Class<?> object, ProcessingElementsContainer container) throws GraphQLAnnotationsException {
4153
String typeName = graphQLObjectInfoRetriever.getTypeName(object);
4254
if (container.getProcessing().contains(typeName)) {

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,43 @@
2424

2525
public class GraphQLInputObjectRetriever {
2626

27+
28+
/**
29+
* This will turn a {@link GraphQLObjectType} into a corresponding {@link GraphQLInputObjectType}
30+
*
31+
* @param graphQLType the graphql object type
32+
* @param newNamePrefix since graphql types MUST be unique, this prefix will be applied to the new input types
33+
* @param typeRegistry object thata saves all the types
34+
* @return a {@link GraphQLInputObjectType}
35+
*/
36+
2737
public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, String newNamePrefix, Map<String, graphql.schema.GraphQLType> typeRegistry) {
2838
if (graphQLType instanceof GraphQLObjectType) {
2939
return HandleGraphQLObjectType((GraphQLObjectType) graphQLType, newNamePrefix, typeRegistry);
3040
} else if (graphQLType instanceof GraphQLList) {
31-
return new GraphQLList(getInputObject(((GraphQLList)graphQLType).getWrappedType(), newNamePrefix,typeRegistry));
41+
return new GraphQLList(getInputObject(((GraphQLList) graphQLType).getWrappedType(), newNamePrefix, typeRegistry));
3242
} else if (graphQLType instanceof graphql.schema.GraphQLNonNull) {
33-
return new graphql.schema.GraphQLNonNull(getInputObject(((GraphQLNonNull)graphQLType).getWrappedType(), newNamePrefix,typeRegistry));
43+
return new graphql.schema.GraphQLNonNull(getInputObject(((GraphQLNonNull) graphQLType).getWrappedType(), newNamePrefix, typeRegistry));
3444
} else if (graphQLType instanceof GraphQLTypeReference) {
3545
return new GraphQLTypeReference(newNamePrefix + (graphQLType).getName());
36-
} else if (graphQLType instanceof GraphQLInputType){
46+
} else if (graphQLType instanceof GraphQLInputType) {
3747
return (GraphQLInputType) graphQLType;
3848
}
39-
throw new IllegalArgumentException("Cannot convert type to input : "+graphQLType);
49+
throw new IllegalArgumentException("Cannot convert type to input : " + graphQLType);
4050
}
4151

4252
private GraphQLInputType HandleGraphQLObjectType(GraphQLObjectType graphQLType, String newNamePrefix, Map<String, GraphQLType> typeRegistry) {
4353
GraphQLObjectType object = graphQLType;
44-
String newObjectName=newNamePrefix + object.getName();
45-
GraphQLType objectInTypeRegistry=typeRegistry.get(newObjectName);
46-
if (objectInTypeRegistry !=null && objectInTypeRegistry instanceof GraphQLInputType) {
54+
String newObjectName = newNamePrefix + object.getName();
55+
GraphQLType objectInTypeRegistry = typeRegistry.get(newObjectName);
56+
if (objectInTypeRegistry != null && objectInTypeRegistry instanceof GraphQLInputType) {
4757
return (GraphQLInputType) objectInTypeRegistry;
4858
}
4959
GraphQLInputObjectType inputObjectType = new GraphQLInputObjectType(newObjectName, object.getDescription(),
5060
object.getFieldDefinitions().stream().
5161
map(field -> {
5262
GraphQLOutputType type = field.getType();
53-
GraphQLInputType inputType = getInputObject(type, newNamePrefix,typeRegistry);
63+
GraphQLInputType inputType = getInputObject(type, newNamePrefix, typeRegistry);
5464
return new GraphQLInputObjectField(field.getName(), field.getDescription(), inputType, null);
5565
}).
5666
collect(Collectors.toList()));

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,32 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
*/
15-
package graphql.annotations.processor.retrievers;
15+
package graphql.annotations;
1616

17-
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
18-
import graphql.annotations.processor.ProcessingElementsContainer;
17+
import graphql.annotations.util.GraphQLOutputObjectRetriever;
18+
import graphql.schema.GraphQLUnionType;
1919

2020
public class GraphQLInterfaceRetriever {
2121

22-
private GraphQLOutputObjectRetriever graphQLOutputObjectRetriever;
22+
private GraphQLOutputObjectRetriever graphQLOutputObjectRetriever;
2323

24-
public GraphQLInterfaceRetriever(GraphQLOutputObjectRetriever graphQLOutputObjectRetriever){
25-
this.graphQLOutputObjectRetriever=graphQLOutputObjectRetriever;
24+
public GraphQLInterfaceRetriever(GraphQLOutputObjectRetriever graphQLOutputObjectRetriever) {
25+
this.graphQLOutputObjectRetriever = graphQLOutputObjectRetriever;
2626
}
2727

28-
public GraphQLInterfaceRetriever(){
28+
public GraphQLInterfaceRetriever() {
2929
this(new GraphQLOutputObjectRetriever());
3030
}
31+
32+
/**
33+
* This will examine the class and return a {@link graphql.schema.GraphQLOutputType} ready for further definition
34+
*
35+
* @param iface interface to examine
36+
* @param container a class that hold several members that are required in order to build schema
37+
* @return a {@link graphql.schema.GraphQLOutputType}
38+
* @throws GraphQLAnnotationsException if the class cannot be examined
39+
*/
3140
public graphql.schema.GraphQLOutputType getInterface(Class<?> iface, ProcessingElementsContainer container) throws GraphQLAnnotationsException {
32-
return graphQLOutputObjectRetriever.getOutputType(iface,container);
41+
return graphQLOutputObjectRetriever.getOutputType(iface, container);
3342
}
3443
}

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
*/
15-
package graphql.annotations.processor.retrievers;
15+
package graphql.annotations.util;
1616

17-
import graphql.annotations.annotations.GraphQLTypeResolver;
18-
import graphql.annotations.annotations.GraphQLUnion;
19-
import graphql.annotations.processor.ProcessingElementsContainer;
20-
import graphql.annotations.processor.exceptions.GraphQLAnnotationsException;
21-
import graphql.annotations.processor.typeBuilders.EnumBuilder;
22-
import graphql.annotations.processor.typeBuilders.InterfaceBuilder;
23-
import graphql.annotations.processor.typeBuilders.ObjectBuilder;
24-
import graphql.annotations.processor.typeBuilders.UnionBuilder;
25-
import graphql.annotations.processor.searchAlgorithms.BreadthFirstSearch;
26-
import graphql.annotations.processor.exceptions.CannotCastMemberException;
27-
import graphql.annotations.processor.searchAlgorithms.ParentalSearch;
28-
import graphql.schema.GraphQLOutputType;
17+
import graphql.annotations.*;
18+
import graphql.annotations.builders.EnumBuilder;
19+
import graphql.annotations.builders.InterfaceBuilder;
20+
import graphql.annotations.builders.ObjectBuilder;
21+
import graphql.annotations.builders.UnionBuilder;
22+
import graphql.annotations.searchAlgorithms.BreadthFirstSearch;
23+
import graphql.annotations.searchAlgorithms.CannotCastMemberException;
24+
import graphql.annotations.searchAlgorithms.ParentalSearch;
25+
import graphql.schema.*;
2926

3027
public class GraphQLOutputObjectRetriever {
3128

@@ -41,6 +38,19 @@ public GraphQLOutputObjectRetriever() {
4138
this(new GraphQLObjectInfoRetriever(), new GraphQLFieldRetriever());
4239
}
4340

41+
/**
42+
* This will examine the object and will return a {@link GraphQLOutputType} based on the class type and annotations.
43+
* - If its annotated with {@link GraphQLUnion} it will return a {@link GraphQLUnionType}
44+
* - If its annotated with {@link GraphQLTypeResolver} it will return a {@link GraphQLInterfaceType}
45+
* - It it's an Enum it will return a {@link GraphQLEnumType},
46+
* otherwise it will return a {@link GraphQLObjectType}.
47+
*
48+
* @param object the object class to examine*
49+
* @param container a class that hold several members that are required in order to build schema
50+
* @return a {@link GraphQLOutputType} that represents that object class
51+
* @throws GraphQLAnnotationsException if the object class cannot be examined
52+
* @throws CannotCastMemberException if the object class cannot be examined
53+
*/
4454
public GraphQLOutputType getOutputType(Class<?> object, ProcessingElementsContainer container) throws GraphQLAnnotationsException, CannotCastMemberException {
4555
// because the TypeFunction can call back to this processor and
4656
// Java classes can be circular, we need to protect against
@@ -61,8 +71,7 @@ public GraphQLOutputType getOutputType(Class<?> object, ProcessingElementsContai
6171
} else if (Enum.class.isAssignableFrom(object)) {
6272
type = new EnumBuilder(graphQLObjectInfoRetriever).getEnumBuilder(object).build();
6373
} else {
64-
InterfaceBuilder interfaceBuilder = new InterfaceBuilder(graphQLObjectInfoRetriever, graphQLFieldRetriever);
65-
type = new ObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), graphQLFieldRetriever, interfaceBuilder,new GraphQLInterfaceRetriever()).getObjectBuilder(object, container, this).build();
74+
type = new ObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), graphQLFieldRetriever, new GraphQLInterfaceRetriever()).getObjectBuilder(object, container).build();
6675
}
6776

6877
container.getTypeRegistry().put(typeName, type);

src/main/java/graphql/annotations/processor/typeBuilders/EnumBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ public EnumBuilder(GraphQLObjectInfoRetriever graphQLObjectInfoRetriever) {
3333
this.graphQLObjectInfoRetriever = graphQLObjectInfoRetriever;
3434
}
3535

36+
/**
37+
* This will examine the object class and return a {@link GraphQLEnumType.Builder} ready for further definition
38+
*
39+
* @param aClass the object class to examine
40+
* @return a {@link GraphQLEnumType.Builder} that represents that object class
41+
*/
42+
3643
public GraphQLEnumType.Builder getEnumBuilder(Class<?> aClass) {
3744
String typeName = graphQLObjectInfoRetriever.getTypeName(aClass);
3845
//noinspection unchecked

0 commit comments

Comments
 (0)