1010import java .util .function .UnaryOperator ;
1111
1212import static graphql .Assert .assertNotNull ;
13- import static graphql .schema .GraphQLTypeUtil .unwrapAll ;
13+ import static graphql .schema .GraphQLTypeUtil .unwrapAllAs ;
1414import static graphql .schema .GraphqlTypeComparatorEnvironment .newEnvironment ;
1515
1616/**
@@ -33,6 +33,7 @@ public class DefaultGraphqlTypeComparatorRegistry implements GraphqlTypeComparat
3333
3434 /**
3535 * This orders the schema into a sensible grouped order
36+ *
3637 * @return a comparator that allows for sensible grouped order
3738 */
3839 public static Comparator <GraphQLSchemaElement > sensibleGroupedOrder () {
@@ -51,15 +52,19 @@ public static Comparator<GraphQLSchemaElement> sensibleGroupedOrder() {
5152
5253 private static GraphQLSchemaElement unwrapElement (GraphQLSchemaElement element ) {
5354 if (element instanceof GraphQLType ) {
54- element = unwrapAll ((GraphQLType ) element );
55+ GraphQLType castElement = (GraphQLType ) element ;
56+ // We need to unwrap as GraphQLType to support GraphQLTypeReferences which is not an GraphQLUnmodifiedType
57+ // as returned by unwrapAll.
58+ castElement = unwrapAllAs (castElement );
59+ element = castElement ;
5560 }
5661 return element ;
5762 }
5863
5964 private static int compareByName (GraphQLSchemaElement o1 , GraphQLSchemaElement o2 ) {
6065 return Comparator .comparing (element -> {
6166 if (element instanceof GraphQLType ) {
62- element = unwrapAll ((GraphQLType ) element );
67+ element = unwrapElement ((GraphQLType ) element );
6368 }
6469 if (element instanceof GraphQLNamedSchemaElement ) {
6570 return ((GraphQLNamedSchemaElement ) element ).getName ();
0 commit comments