@@ -220,16 +220,14 @@ else if (typePair.outputType() instanceof GraphQLInterfaceType interfaceType) {
220
220
// Can we inspect GraphQL type?
221
221
if (!(graphQlType instanceof GraphQLFieldsContainer fieldContainer )) {
222
222
if (isNotScalarOrEnumType (graphQlType )) {
223
- FieldCoordinates coordinates = FieldCoordinates .coordinates (parent .getName (), field .getName ());
224
- addSkippedType (graphQlType , coordinates , "Unsupported schema type" );
223
+ this .reportBuilder .skippedType (graphQlType , parent , field , "Unsupported schema type" );
225
224
}
226
225
continue ;
227
226
}
228
227
229
228
// Can we inspect the Class?
230
229
if (currentResolvableType .resolve (Object .class ) == Object .class ) {
231
- FieldCoordinates coordinates = FieldCoordinates .coordinates (parent .getName (), field .getName ());
232
- addSkippedType (graphQlType , coordinates , "No class information" );
230
+ this .reportBuilder .skippedType (graphQlType , parent , field , "No class information" );
233
231
continue ;
234
232
}
235
233
@@ -254,18 +252,6 @@ private static boolean isNotScalarOrEnumType(GraphQLType type) {
254
252
return !(type instanceof GraphQLScalarType || type instanceof GraphQLEnumType );
255
253
}
256
254
257
- private void addSkippedType (GraphQLType type , FieldCoordinates coordinates , String reason ) {
258
- String typeName = typeNameToString (type );
259
- this .reportBuilder .skippedType (type , coordinates );
260
- if (logger .isDebugEnabled ()) {
261
- logger .debug ("Skipped '" + typeName + "': " + reason );
262
- }
263
- }
264
-
265
- private static String typeNameToString (GraphQLType type ) {
266
- return (type instanceof GraphQLNamedType namedType ) ? namedType .getName () : type .toString ();
267
- }
268
-
269
255
private void checkDataFetcherRegistrations () {
270
256
this .dataFetchers .forEach ((typeName , registrations ) ->
271
257
registrations .forEach ((fieldName , dataFetcher ) -> {
@@ -469,6 +455,7 @@ public static ReflectionClassResolver create(
469
455
Function <GraphQLObjectType , String > classNameFunction ) {
470
456
471
457
MultiValueMap <String , String > classPrefixes = new LinkedMultiValueMap <>();
458
+
472
459
for (Map .Entry <String , Map <String , DataFetcher >> typeEntry : dataFetchers .entrySet ()) {
473
460
String typeName = typeEntry .getKey ();
474
461
GraphQLType parentType = schema .getType (typeName );
@@ -481,27 +468,33 @@ public static ReflectionClassResolver create(
481
468
if (field == null ) {
482
469
continue ; // Unmapped registration
483
470
}
484
- TypePair pair = TypePair .resolveTypePair (parentType , field , fieldEntry .getValue (), schema );
471
+ DataFetcher dataFetcher = fieldEntry .getValue ();
472
+ TypePair pair = TypePair .resolveTypePair (parentType , field , dataFetcher , schema );
485
473
GraphQLType outputType = pair .outputType ();
486
474
if (outputType instanceof GraphQLUnionType || outputType instanceof GraphQLInterfaceType ) {
487
475
String outputTypeName = ((GraphQLNamedOutputType ) outputType ).getName ();
488
476
Class <?> clazz = pair .resolvableType ().resolve (Object .class );
489
477
if (PACKAGE_PREDICATE .test (clazz .getPackageName ())) {
490
- int index = clazz .getName ().indexOf (clazz .getSimpleName ());
491
- classPrefixes .add (outputTypeName , clazz .getName ().substring (0 , index ));
478
+ addClassPrefix (outputTypeName , clazz , classPrefixes );
492
479
}
493
- else if (fieldEntry .getValue () instanceof SelfDescribingDataFetcher <?> sddf ) {
494
- if (sddf .getReturnType ().getSource () instanceof MethodParameter param ) {
495
- clazz = param .getDeclaringClass ();
496
- int index = clazz .getName ().indexOf (clazz .getSimpleName ());
497
- classPrefixes .add (outputTypeName , clazz .getName ().substring (0 , index ));
480
+ else if (dataFetcher instanceof SelfDescribingDataFetcher <?> selfDescribing ) {
481
+ if (selfDescribing .getReturnType ().getSource () instanceof MethodParameter param ) {
482
+ addClassPrefix (outputTypeName , param .getDeclaringClass (), classPrefixes );
498
483
}
499
484
}
500
485
}
501
486
}
502
487
}
488
+
503
489
return new ReflectionClassResolver (classNameFunction , classPrefixes );
504
490
}
491
+
492
+ private static void addClassPrefix (
493
+ String unionOrInterfaceType , Class <?> aClass , MultiValueMap <String , String > classPrefixes ) {
494
+
495
+ int index = aClass .getName ().indexOf (aClass .getSimpleName ());
496
+ classPrefixes .add (unionOrInterfaceType , aClass .getName ().substring (0 , index ));
497
+ }
505
498
}
506
499
507
500
@@ -744,8 +737,12 @@ void unmappedArgument(DataFetcher<?> dataFetcher, List<String> arguments) {
744
737
this .unmappedArguments .put (dataFetcher , arguments );
745
738
}
746
739
747
- void skippedType (GraphQLType type , FieldCoordinates coordinates ) {
748
- this .skippedTypes .add (new DefaultSkippedType (type , coordinates ));
740
+ void skippedType (GraphQLType type , GraphQLFieldsContainer parent , GraphQLFieldDefinition field , String reason ) {
741
+ DefaultSkippedType skippedType = DefaultSkippedType .create (type , parent , field );
742
+ if (logger .isDebugEnabled ()) {
743
+ logger .debug ("Skipping '" + skippedType + "': " + reason );
744
+ }
745
+ this .skippedTypes .add (skippedType );
749
746
}
750
747
751
748
SchemaReport build () {
@@ -759,7 +756,7 @@ SchemaReport build() {
759
756
/**
760
757
* Default implementation of {@link SchemaReport}.
761
758
*/
762
- private class DefaultSchemaReport implements SchemaReport {
759
+ private final class DefaultSchemaReport implements SchemaReport {
763
760
764
761
private final List <FieldCoordinates > unmappedFields ;
765
762
@@ -841,9 +838,14 @@ private record DefaultSkippedType(
841
838
842
839
@ Override
843
840
public String toString () {
844
- return typeNameToString ( this . type );
841
+ return ( type instanceof GraphQLNamedType namedType ) ? namedType . getName () : type . toString ( );
845
842
}
846
843
844
+ public static DefaultSkippedType create (
845
+ GraphQLType type , GraphQLFieldsContainer parent , GraphQLFieldDefinition field ) {
846
+
847
+ return new DefaultSkippedType (type , FieldCoordinates .coordinates (parent , field ));
848
+ }
847
849
}
848
850
849
851
}
0 commit comments