@@ -684,8 +684,9 @@ public static TypePair resolveTypePair(
684
684
685
685
// Remove GraphQL type wrappers, and nest within Java generic types
686
686
GraphQLType outputType = unwrapIfNonNull (field .getType ());
687
- if (isPaginatedType (outputType )) {
688
- outputType = getPaginatedType ((GraphQLObjectType ) outputType , schema );
687
+ GraphQLType paginatedType = getPaginatedType (outputType );
688
+ if (paginatedType != null ) {
689
+ outputType = paginatedType ;
689
690
resolvableType = nestForConnection (resolvableType );
690
691
}
691
692
else if (outputType instanceof GraphQLList listType ) {
@@ -702,17 +703,26 @@ private static GraphQLType unwrapIfNonNull(GraphQLType type) {
702
703
return (type instanceof GraphQLNonNull graphQLNonNull ) ? graphQLNonNull .getWrappedType () : type ;
703
704
}
704
705
705
- private static boolean isPaginatedType (GraphQLType type ) {
706
- return (type instanceof GraphQLObjectType objectType &&
707
- objectType .getName ().endsWith ("Connection" ) &&
708
- objectType .getField ("edges" ) != null && objectType .getField ("pageInfo" ) != null );
709
- }
710
-
711
- private static GraphQLType getPaginatedType (GraphQLObjectType type , GraphQLSchema schema ) {
712
- String name = type .getName ().substring (0 , type .getName ().length () - 10 );
713
- GraphQLType nodeType = schema .getType (name );
714
- Assert .state (nodeType != null , "No node type for '" + type .getName () + "'" );
715
- return nodeType ;
706
+ @ Nullable
707
+ private static GraphQLType getPaginatedType (GraphQLType type ) {
708
+ if (!(type instanceof GraphQLObjectType cot && cot .getName ().endsWith ("Connection" ))) {
709
+ return null ;
710
+ }
711
+ GraphQLFieldDefinition edges = cot .getField ("edges" );
712
+ if (edges == null ) {
713
+ return null ;
714
+ }
715
+ if (!(unwrapIfNonNull (edges .getType ()) instanceof GraphQLList lt )) {
716
+ return null ;
717
+ }
718
+ if (!(lt .getWrappedType () instanceof GraphQLObjectType eot )) {
719
+ return null ;
720
+ }
721
+ GraphQLFieldDefinition node = eot .getField ("node" );
722
+ if (node == null ) {
723
+ return null ;
724
+ }
725
+ return unwrapIfNonNull (node .getType ());
716
726
}
717
727
718
728
private static ResolvableType nestForConnection (ResolvableType type ) {
0 commit comments