@@ -473,7 +473,8 @@ protected GraphQLFieldDefinition getField(Field field) throws GraphQLAnnotations
473473
474474 boolean isConnection = isConnection (field , outputType );
475475 if (isConnection ) {
476- outputType = getGraphQLConnection (field , outputType , builder );
476+ outputType = getGraphQLConnection (field , outputType );
477+ builder .argument (relay .getConnectionFieldArguments ());
477478 }
478479
479480 builder .type (outputType );
@@ -574,23 +575,29 @@ private boolean checkIfPrefixGetterExists(Class c, String prefix, String propert
574575 return true ;
575576 }
576577
577- private GraphQLOutputType getGraphQLConnection (AccessibleObject field , GraphQLOutputType type , GraphQLFieldDefinition . Builder builder ) {
578+ private GraphQLOutputType getGraphQLConnection (AccessibleObject field , GraphQLOutputType type ) {
578579 if (type instanceof GraphQLNonNull ) {
579- type = (GraphQLOutputType ) ((GraphQLNonNull ) type ).getWrappedType ();
580- return new GraphQLNonNull (internalGetGraphQLConnection (field , type , builder ));
580+ GraphQLList listType = (GraphQLList ) ((GraphQLNonNull ) type ).getWrappedType ();
581+ return new GraphQLNonNull (internalGetGraphQLConnection (field , listType ));
581582 } else {
582- return internalGetGraphQLConnection (field , type , builder );
583+ return internalGetGraphQLConnection (field , ( GraphQLList ) type );
583584 }
584585 }
585586
586- private GraphQLOutputType internalGetGraphQLConnection (AccessibleObject field , GraphQLOutputType type , GraphQLFieldDefinition .Builder builder ) {
587- graphql .schema .GraphQLType wrappedType = ((GraphQLList ) type ).getWrappedType ();
588- assert wrappedType instanceof GraphQLObjectType ;
587+ private GraphQLOutputType internalGetGraphQLConnection (AccessibleObject field , GraphQLList listType ) {
588+ GraphQLOutputType wrappedType = (GraphQLOutputType ) listType .getWrappedType ();
589589 String connectionName = field .getAnnotation (GraphQLConnection .class ).name ();
590590 connectionName = connectionName .isEmpty () ? wrappedType .getName () : connectionName ;
591- GraphQLObjectType edgeType = relay .edgeType (connectionName , (GraphQLOutputType ) wrappedType , null , Collections .<GraphQLFieldDefinition >emptyList ());
592- type = relay .connectionType (connectionName , edgeType , Collections .emptyList ());
593- builder .argument (relay .getConnectionFieldArguments ());
591+ GraphQLObjectType edgeType = getActualType (relay .edgeType (connectionName , wrappedType , null , Collections .<GraphQLFieldDefinition >emptyList ()));
592+ return getActualType (relay .connectionType (connectionName , edgeType , Collections .emptyList ()));
593+ }
594+
595+ private GraphQLObjectType getActualType (GraphQLObjectType type ) {
596+ if (typeRegistry .containsKey (type .getName ())) {
597+ type = (GraphQLObjectType ) typeRegistry .get (type .getName ());
598+ } else {
599+ typeRegistry .put (type .getName (), type );
600+ }
594601 return type ;
595602 }
596603
@@ -630,7 +637,8 @@ protected GraphQLFieldDefinition getField(Method method) throws GraphQLAnnotatio
630637
631638 boolean isConnection = isConnection (method , outputType );
632639 if (isConnection ) {
633- outputType = getGraphQLConnection (method , outputType , builder );
640+ outputType = getGraphQLConnection (method , outputType );
641+ builder .argument (relay .getConnectionFieldArguments ());
634642 }
635643
636644 builder .type (outputType );
0 commit comments