Skip to content

Commit dbcc9be

Browse files
committed
Added to "isConnection" method a validate process that checks if the
type of the field/method is instance of "PaginatedData"
1 parent 49b896e commit dbcc9be

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/main/java/graphql/annotations/GraphQLAnnotations.java

Lines changed: 21 additions & 12 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,
@@ -16,6 +16,7 @@
1616

1717
import graphql.TypeResolutionEnvironment;
1818
import graphql.annotations.connection.ConnectionDataFetcher;
19+
import graphql.annotations.connection.ConnectionTypeValidator;
1920
import graphql.annotations.connection.GraphQLConnection;
2021
import graphql.relay.Relay;
2122
import graphql.schema.*;
@@ -179,7 +180,6 @@ private static Boolean isGraphQLField(AnnotatedElement element) {
179180
* breadthFirst parental ascent looking for closest method declaration with explicit annotation
180181
*
181182
* @param method The method to match
182-
*
183183
* @return The closest GraphQLField annotation
184184
*/
185185
private boolean breadthFirstSearch(Method method) {
@@ -221,7 +221,6 @@ private boolean breadthFirstSearch(Method method) {
221221
* direct parental ascent looking for closest declaration with explicit annotation
222222
*
223223
* @param field The field to find
224-
*
225224
* @return The closest GraphQLField annotation
226225
*/
227226
private boolean parentalSearch(Field field) {
@@ -247,7 +246,7 @@ public GraphQLObjectType getObject(Class<?> object) throws GraphQLAnnotationsExc
247246
if (type instanceof GraphQLObjectType) {
248247
return (GraphQLObjectType) type;
249248
} else {
250-
throw new IllegalArgumentException("Object resolve to a "+type.getClass().getSimpleName());
249+
throw new IllegalArgumentException("Object resolve to a " + type.getClass().getSimpleName());
251250
}
252251
}
253252

@@ -313,7 +312,7 @@ public GraphQLEnumType.Builder getEnumBuilder(Class<?> aClass) {
313312
return builder;
314313
}
315314

316-
public static GraphQLEnumType.Builder enumBuilder(Class<?> object) throws GraphQLAnnotationsException {
315+
public static GraphQLEnumType.Builder enumBuilder(Class<?> object) throws GraphQLAnnotationsException {
317316
return getInstance().getEnumBuilder(object);
318317
}
319318

@@ -604,12 +603,22 @@ private GraphQLObjectType getActualType(GraphQLObjectType type) {
604603
}
605604

606605
private boolean isConnection(AccessibleObject obj, GraphQLOutputType type) {
606+
ConnectionTypeValidator validator = new ConnectionTypeValidator();
607607
if (type instanceof GraphQLNonNull) {
608608
type = (GraphQLOutputType) ((GraphQLNonNull) type).getWrappedType();
609609
}
610610
final GraphQLOutputType actualType = type;
611-
return obj.isAnnotationPresent(GraphQLConnection.class) &&
612-
actualType instanceof GraphQLList && TYPES_FOR_CONNECTION.stream().anyMatch(aClass -> aClass.isInstance(((GraphQLList) actualType).getWrappedType()));
611+
612+
boolean isValidGraphQLTypeForConnection = obj.isAnnotationPresent(GraphQLConnection.class) &&
613+
actualType instanceof GraphQLList && TYPES_FOR_CONNECTION.stream().anyMatch(aClass ->
614+
aClass.isInstance(((GraphQLList) actualType).getWrappedType()));
615+
616+
if(isValidGraphQLTypeForConnection) {
617+
validator.validate(obj);
618+
return true;
619+
} else {
620+
return false;
621+
}
613622
}
614623

615624
protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotationsException {
@@ -747,15 +756,15 @@ public GraphQLInputType getInputObject(graphql.schema.GraphQLType graphQLType, S
747756
typeRegistry.put(inputObjectType.getName(), inputObjectType);
748757
return inputObjectType;
749758
} else if (graphQLType instanceof GraphQLList) {
750-
return new GraphQLList(getInputObject(((GraphQLList)graphQLType).getWrappedType(), newNamePrefix));
759+
return new GraphQLList(getInputObject(((GraphQLList) graphQLType).getWrappedType(), newNamePrefix));
751760
} else if (graphQLType instanceof GraphQLNonNull) {
752-
return new GraphQLNonNull(getInputObject(((GraphQLNonNull)graphQLType).getWrappedType(), newNamePrefix));
761+
return new GraphQLNonNull(getInputObject(((GraphQLNonNull) graphQLType).getWrappedType(), newNamePrefix));
753762
} else if (graphQLType instanceof GraphQLTypeReference) {
754-
return new GraphQLTypeReference(newNamePrefix + ((GraphQLTypeReference)graphQLType).getName());
755-
} else if (graphQLType instanceof GraphQLInputType){
763+
return new GraphQLTypeReference(newNamePrefix + ((GraphQLTypeReference) graphQLType).getName());
764+
} else if (graphQLType instanceof GraphQLInputType) {
756765
return (GraphQLInputType) graphQLType;
757766
}
758-
throw new IllegalArgumentException("Cannot convert type to input : "+graphQLType);
767+
throw new IllegalArgumentException("Cannot convert type to input : " + graphQLType);
759768
}
760769

761770
public static GraphQLInputObjectType inputObject(GraphQLObjectType graphQLType, String newNamePrefix) {

0 commit comments

Comments
 (0)