80
80
* @author Rossen Stoyanchev
81
81
* @since 1.2.0
82
82
*/
83
+ @ SuppressWarnings ("rawtypes" )
83
84
public class SchemaMappingInspector {
84
85
85
86
private static final Log logger = LogFactory .getLog (SchemaMappingInspector .class );
86
87
87
88
88
89
private final GraphQLSchema schema ;
89
90
90
- private final RuntimeWiring runtimeWiring ;
91
+ private final Map < String , Map < String , DataFetcher >> dataFetchers ;
91
92
92
93
private final Set <String > inspectedTypes = new HashSet <>();
93
94
@@ -99,11 +100,11 @@ public class SchemaMappingInspector {
99
100
private SchemaReport report ;
100
101
101
102
102
- private SchemaMappingInspector (GraphQLSchema schema , RuntimeWiring runtimeWiring ) {
103
+ private SchemaMappingInspector (GraphQLSchema schema , Map < String , Map < String , DataFetcher >> dataFetchers ) {
103
104
Assert .notNull (schema , "GraphQLSchema is required" );
104
- Assert .notNull (runtimeWiring , "RuntimeWiring is required" );
105
+ Assert .notNull (dataFetchers , "DataFetcher map is required" );
105
106
this .schema = schema ;
106
- this .runtimeWiring = runtimeWiring ;
107
+ this .dataFetchers = dataFetchers ;
107
108
}
108
109
109
110
@@ -140,11 +141,10 @@ private void checkSchemaFields() {
140
141
* @param resolvableType the Java type to match against, or {@code null} if
141
142
* not applicable such as for Query, Mutation, or Subscription
142
143
*/
143
- @ SuppressWarnings ("rawtypes" )
144
144
private void checkFieldsContainer (GraphQLFieldsContainer fieldContainer , @ Nullable ResolvableType resolvableType ) {
145
145
146
146
String typeName = fieldContainer .getName ();
147
- Map <String , DataFetcher > dataFetcherMap = this .runtimeWiring . getDataFetcherForType (typeName );
147
+ Map <String , DataFetcher > dataFetcherMap = this .dataFetchers . getOrDefault (typeName , Collections . emptyMap () );
148
148
149
149
for (GraphQLFieldDefinition field : fieldContainer .getFieldDefinitions ()) {
150
150
String fieldName = field .getName ();
@@ -307,9 +307,8 @@ private void addSkippedType(GraphQLType type, FieldCoordinates coordinates, Stri
307
307
}
308
308
}
309
309
310
- @ SuppressWarnings ("rawtypes" )
311
310
private void checkDataFetcherRegistrations () {
312
- this .runtimeWiring . getDataFetchers () .forEach ((typeName , registrations ) ->
311
+ this .dataFetchers .forEach ((typeName , registrations ) ->
313
312
registrations .forEach ((fieldName , dataFetcher ) -> {
314
313
FieldCoordinates coordinates = FieldCoordinates .coordinates (typeName , fieldName );
315
314
if (this .schema .getFieldDefinition (coordinates ) == null ) {
@@ -326,7 +325,16 @@ private void checkDataFetcherRegistrations() {
326
325
* @return the created report
327
326
*/
328
327
public static SchemaReport inspect (GraphQLSchema schema , RuntimeWiring runtimeWiring ) {
329
- return new SchemaMappingInspector (schema , runtimeWiring ).getOrCreateReport ();
328
+ return inspect (schema , runtimeWiring .getDataFetchers ());
329
+ }
330
+
331
+ /**
332
+ * Variant of {@link #inspect(GraphQLSchema, RuntimeWiring)} with a map of
333
+ * {@code DataFetcher} registrations.
334
+ * @since 1.2.5
335
+ */
336
+ public static SchemaReport inspect (GraphQLSchema schema , Map <String , Map <String , DataFetcher >> dataFetchers ) {
337
+ return new SchemaMappingInspector (schema , dataFetchers ).getOrCreateReport ();
330
338
}
331
339
332
340
@@ -403,8 +411,8 @@ public GraphQLSchema schema() {
403
411
@ Override
404
412
@ Nullable
405
413
public DataFetcher <?> dataFetcher (FieldCoordinates coordinates ) {
406
- return SchemaMappingInspector .this .runtimeWiring
407
- .getDataFetcherForType (coordinates .getTypeName ())
414
+ return SchemaMappingInspector .this .dataFetchers
415
+ .getOrDefault (coordinates .getTypeName (), Collections . emptyMap ())
408
416
.get (coordinates .getFieldName ());
409
417
}
410
418
0 commit comments