Skip to content

Commit 2d3a362

Browse files
committed
fixing code review,
removing unneeded lines of codes
1 parent 17df6c6 commit 2d3a362

File tree

6 files changed

+34
-52
lines changed

6 files changed

+34
-52
lines changed

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

Lines changed: 5 additions & 21 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.
@@ -54,22 +54,6 @@ public GraphQLInputType getInputTypeOrRef(Class<?> object, ProcessingElementsCon
5454
if (Enum.class.isAssignableFrom(object)) {
5555
considerAsInput = false;
5656
}
57-
58-
String typeName = DEFAULT_INPUT_PREFIX +graphQLObjectInfoRetriever.getTypeName(object);
59-
60-
if (container.getProcessing().contains(typeName)){
61-
return new GraphQLTypeReference(typeName);
62-
}
63-
64-
Map<String, GraphQLType> typeRegistry = container.getTypeRegistry();
65-
66-
if (typeRegistry.containsKey(typeName)) {
67-
return (GraphQLInputType) container.getTypeRegistry().get(typeName);
68-
} else {
69-
70-
GraphQLInputType graphQLType = (GraphQLInputType) graphQLTypeRetriever.getGraphQLType(object, container, considerAsInput);
71-
typeRegistry.put(graphQLType.getName(), graphQLType);
72-
return graphQLType;
73-
}
57+
return (GraphQLInputType) graphQLTypeRetriever.getGraphQLType(object, container, considerAsInput);
7458
}
7559
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ public GraphQLOutputProcessor() {
5050
*/
5151

5252
public GraphQLOutputType getOutputTypeOrRef(Class<?> object, ProcessingElementsContainer container) throws GraphQLAnnotationsException {
53-
String typeName = graphQLObjectInfoRetriever.getTypeName(object);
54-
if (container.getProcessing().contains(typeName)) {
55-
return new GraphQLTypeReference(typeName);
56-
}
57-
5853
return (GraphQLOutputType) graphQLTypeRetriever.getGraphQLType(object, container, false);
5954
}
6055

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import graphql.annotations.GraphQLFieldDefinitionWrapper;
1919
import graphql.annotations.annotationTypes.GraphQLRelayMutation;
20-
import graphql.annotations.annotationTypes.GraphQLType;
2120
import graphql.annotations.connection.GraphQLConnection;
2221
import graphql.annotations.processor.ProcessingElementsContainer;
2322
import graphql.annotations.processor.exceptions.CannotCastMemberException;
@@ -47,7 +46,7 @@
4746
import java.util.List;
4847
import java.util.Map;
4948
import java.util.stream.Collectors;
50-
49+
import graphql.schema.GraphQLType;
5150
import static graphql.annotations.processor.util.ObjectUtil.getAllFields;
5251
import static graphql.annotations.processor.util.ReflectionKit.newInstance;
5352
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
@@ -73,7 +72,7 @@ public GraphQLFieldRetriever() {
7372
this(new GraphQLObjectInfoRetriever(), new BreadthFirstSearch(new GraphQLObjectInfoRetriever()), new ParentalSearch(new GraphQLObjectInfoRetriever()), new DataFetcherConstructor());
7473
}
7574

76-
public List<GraphQLFieldDefinition> getExtensionFields(Class<?> object, List<String> fieldsDefined, ProcessingElementsContainer container) throws CannotCastMemberException {
75+
public List<GraphQLFieldDefinition> getExtensionFields(Class<?> object, List<String> definedFields, ProcessingElementsContainer container) throws CannotCastMemberException {
7776
List<GraphQLFieldDefinition> fields = new ArrayList<>();
7877
if (container.getExtensionsTypeRegistry().containsKey(object)) {
7978
for (Class<?> aClass : container.getExtensionsTypeRegistry().get(object)) {
@@ -82,15 +81,15 @@ public List<GraphQLFieldDefinition> getExtensionFields(Class<?> object, List<Str
8281
continue;
8382
}
8483
if (breadthFirstSearch.isFound(method)) {
85-
addExtensionField(getField(method, container), fields, fieldsDefined);
84+
addExtensionField(getField(method, container), fields, definedFields);
8685
}
8786
}
8887
for (Field field : getAllFields(aClass).values()) {
8988
if (Modifier.isStatic(field.getModifiers())) {
9089
continue;
9190
}
9291
if (parentalSearch.isFound(field)) {
93-
addExtensionField(getField(field, container), fields, fieldsDefined);
92+
addExtensionField(getField(field, container), fields, definedFields);
9493
}
9594
}
9695
}
@@ -123,7 +122,7 @@ public GraphQLFieldDefinition getField(Field field, ProcessingElementsContainer
123122
builder.name(new FieldNameBuilder(field).build());
124123
TypeFunction typeFunction = getTypeFunction(field, container);
125124

126-
graphql.schema.GraphQLType outputType = typeFunction.buildType(field.getType(), field.getAnnotatedType(), container);
125+
GraphQLType outputType = typeFunction.buildType(field.getType(), field.getAnnotatedType(), container);
127126
boolean isConnection = ConnectionUtil.isConnection(field, outputType);
128127
if (isConnection) {
129128
outputType = getGraphQLConnection(field, outputType, container.getRelay(), container.getTypeRegistry());
@@ -149,7 +148,7 @@ public GraphQLInputObjectField getInputField(Field field, ProcessingElementsCont
149148
GraphQLInputObjectField.Builder builder = newInputObjectField();
150149
builder.name(new FieldNameBuilder(field).build());
151150
TypeFunction typeFunction = getTypeFunction(field, container);
152-
graphql.schema.GraphQLType graphQLType = typeFunction.buildType(true,field.getType(), field.getAnnotatedType(), container);
151+
GraphQLType graphQLType = typeFunction.buildType(true,field.getType(), field.getAnnotatedType(), container);
153152
return builder.type((GraphQLInputType) graphQLType).description(new DescriptionBuilder(field).build()).build();
154153
}
155154

@@ -170,7 +169,7 @@ private void handleConnectionArgument(ProcessingElementsContainer container, Gra
170169
}
171170

172171
private TypeFunction getTypeFunction(Method method, ProcessingElementsContainer container) {
173-
GraphQLType annotation = method.getAnnotation(GraphQLType.class);
172+
graphql.annotations.annotationTypes.GraphQLType annotation = method.getAnnotation(graphql.annotations.annotationTypes.GraphQLType.class);
174173
TypeFunction typeFunction = container.getDefaultTypeFunction();
175174

176175
if (annotation != null) {
@@ -200,7 +199,7 @@ private GraphQLFieldDefinition buildRelayMutation(Method method, ProcessingEleme
200199

201200

202201
private TypeFunction getTypeFunction(Field field, ProcessingElementsContainer container) {
203-
GraphQLType annotation = field.getAnnotation(GraphQLType.class);
202+
graphql.annotations.annotationTypes.GraphQLType annotation = field.getAnnotation(graphql.annotations.annotationTypes.GraphQLType.class);
204203

205204
TypeFunction typeFunction = container.getDefaultTypeFunction();
206205

@@ -227,9 +226,9 @@ private GraphQLOutputType internalGetGraphQLConnection(AccessibleObject field, G
227226
return getActualType(relay.connectionType(connectionName, edgeType, Collections.emptyList()), typeRegistry);
228227
}
229228

230-
private void addExtensionField(GraphQLFieldDefinition gqlField, List<GraphQLFieldDefinition> fields, List<String> fieldsDefined) {
231-
if (!fieldsDefined.contains(gqlField.getName())) {
232-
fieldsDefined.add(gqlField.getName());
229+
private void addExtensionField(GraphQLFieldDefinition gqlField, List<GraphQLFieldDefinition> fields, List<String> definedFields) {
230+
if (!definedFields.contains(gqlField.getName())) {
231+
definedFields.add(gqlField.getName());
233232
fields.add(gqlField);
234233
} else {
235234
throw new GraphQLAnnotationsException("Duplicate field found in extension : " + gqlField.getName(), null);

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

Lines changed: 10 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.
@@ -60,11 +60,16 @@ public GraphQLType getGraphQLType(Class<?> object, ProcessingElementsContainer c
6060
// all type instances to be unique singletons
6161
String typeName = graphQLObjectInfoRetriever.getTypeName(object);
6262
GraphQLType type;
63+
6364
if (isInput) {
6465
typeName = DEFAULT_INPUT_PREFIX + typeName;
6566

6667
}
6768

69+
if (container.getProcessing().contains(typeName)) {
70+
return new GraphQLTypeReference(typeName);
71+
}
72+
6873
type = container.getTypeRegistry().get(typeName);
6974
if (type != null) return type;
7075

@@ -82,8 +87,7 @@ public GraphQLType getGraphQLType(Class<?> object, ProcessingElementsContainer c
8287
if (isInput) {
8388
type = new InputObjectBuilder(graphQLObjectInfoRetriever, parentalSearch,
8489
breadthFirstSearch, graphQLFieldRetriever).getInputObjectBuilder(object, container).build();
85-
}
86-
else{
90+
} else {
8791
type = new OutputObjectBuilder(graphQLObjectInfoRetriever, parentalSearch,
8892
breadthFirstSearch, graphQLFieldRetriever, new GraphQLInterfaceRetriever()).getOutputObjectBuilder(object, container).build();
8993
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public GraphQLInputObjectType.Builder getInputObjectBuilder(Class<?> object, Pro
6363
builder.description(description.value());
6464
}
6565

66-
List<String> fieldsDefined = new ArrayList<>();
66+
List<String> definedFields = new ArrayList<>();
6767

6868
for (Method method : graphQLObjectInfoRetriever.getOrderedMethods(object)) {
6969
if (method.isBridge() || method.isSynthetic()) {
7070
continue;
7171
}
7272
if (breadthFirstSearch.isFound(method)) {
7373
GraphQLInputObjectField gqlField = graphQLFieldRetriever.getInputField(method,container);
74-
fieldsDefined.add(gqlField.getName());
74+
definedFields.add(gqlField.getName());
7575
builder.field(gqlField);
7676
}
7777
}
@@ -82,7 +82,7 @@ public GraphQLInputObjectType.Builder getInputObjectBuilder(Class<?> object, Pro
8282
}
8383
if (parentalSearch.isFound(field)) {
8484
GraphQLInputObjectField gqlField = graphQLFieldRetriever.getInputField(field,container);
85-
fieldsDefined.add(gqlField.getName());
85+
definedFields.add(gqlField.getName());
8686
builder.field(gqlField);
8787
}
8888
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ public GraphQLObjectType.Builder getOutputObjectBuilder(Class<?> object, Process
6969
if (description != null) {
7070
builder.description(description.value());
7171
}
72-
List<String> fieldsDefined = new ArrayList<>();
72+
List<String> definedFields = new ArrayList<>();
7373
for (Method method : graphQLObjectInfoRetriever.getOrderedMethods(object)) {
7474
if (method.isBridge() || method.isSynthetic()) {
7575
continue;
7676
}
7777
if (breadthFirstSearch.isFound(method)) {
7878
GraphQLFieldDefinition gqlField = graphQLFieldRetriever.getField(method,container);
79-
fieldsDefined.add(gqlField.getName());
79+
definedFields.add(gqlField.getName());
8080
builder.field(gqlField);
8181
}
8282
}
@@ -87,7 +87,7 @@ public GraphQLObjectType.Builder getOutputObjectBuilder(Class<?> object, Process
8787
}
8888
if (parentalSearch.isFound(field)) {
8989
GraphQLFieldDefinition gqlField = graphQLFieldRetriever.getField(field,container);
90-
fieldsDefined.add(gqlField.getName());
90+
definedFields.add(gqlField.getName());
9191
builder.field(gqlField);
9292
}
9393
}
@@ -100,11 +100,11 @@ public GraphQLObjectType.Builder getOutputObjectBuilder(Class<?> object, Process
100100
} else {
101101
builder.withInterface((GraphQLInterfaceType) graphQLInterfaceRetriever.getInterface(iface,container));
102102
}
103-
builder.fields(graphQLFieldRetriever.getExtensionFields(iface, fieldsDefined,container));
103+
builder.fields(graphQLFieldRetriever.getExtensionFields(iface, definedFields,container));
104104
}
105105
}
106106

107-
builder.fields(graphQLFieldRetriever.getExtensionFields(object, fieldsDefined,container));
107+
builder.fields(graphQLFieldRetriever.getExtensionFields(object, definedFields,container));
108108

109109
return builder;
110110
}

0 commit comments

Comments
 (0)