21
21
import java .util .LinkedHashSet ;
22
22
import java .util .Map ;
23
23
import java .util .Set ;
24
+ import java .util .function .Supplier ;
24
25
25
26
import graphql .schema .DataFetcher ;
26
27
import graphql .schema .FieldCoordinates ;
@@ -147,11 +148,8 @@ private void inspectFields(GraphQLFieldsContainer fields, @Nullable ResolvableTy
147
148
(fields == this .schema .getSubscriptionType ()));
148
149
}
149
150
else if (isNotScalarOrEnumType (field .getType ())) {
150
- if (logger .isDebugEnabled ()) {
151
- logger .debug ("Skipped '" + typeNameToString (field .getType ()) + "': " +
152
- fetcher .getClass ().getName () + " does not implement SelfDescribingDataFetcher." );
153
- }
154
- this .reportBuilder .addSkippedType (typeNameToString (field .getType ()));
151
+ addSkippedType (field .getType (), () ->
152
+ fetcher .getClass ().getName () + " does not implement SelfDescribingDataFetcher." );
155
153
}
156
154
}
157
155
else if (resolvableType == null || !hasProperty (resolvableType , fieldName )) {
@@ -170,8 +168,8 @@ private void inspectFieldType(GraphQLType outputType, ResolvableType resolvableT
170
168
171
169
// Remove GraphQL type wrappers, and nest within Java generic types
172
170
outputType = unwrapIfNonNull (outputType );
173
- if (isConnectionType (outputType )) {
174
- outputType = getConnectionNodeType ( outputType );
171
+ if (isPaginatedType (outputType )) {
172
+ outputType = getPaginatedType (( GraphQLObjectType ) outputType );
175
173
resolvableType = nestForConnection (resolvableType );
176
174
}
177
175
else if (outputType instanceof GraphQLList listType ) {
@@ -190,22 +188,15 @@ else if (outputType instanceof GraphQLList listType) {
190
188
// Can we inspect GraphQL type?
191
189
if (!(outputType instanceof GraphQLFieldsContainer fieldContainer )) {
192
190
if (isNotScalarOrEnumType (outputType )) {
193
- if (logger .isDebugEnabled ()) {
194
- logger .debug ("Skipped '" + typeNameToString (outputType ) + "': " +
195
- "inspection does not support " + outputType .getClass ().getSimpleName () + "." );
196
- }
197
- this .reportBuilder .addSkippedType (typeNameToString (outputType ));
191
+ String schemaTypeName = outputType .getClass ().getSimpleName ();
192
+ addSkippedType (outputType , () -> "inspection does not support " + schemaTypeName + "." );
198
193
}
199
194
return ;
200
195
}
201
196
202
197
// Can we inspect Java type?
203
198
if (resolvableType .resolve (Object .class ) == Object .class ) {
204
- if (logger .isDebugEnabled ()) {
205
- logger .debug ("Skipped '" + typeNameToString (outputType ) + "': " +
206
- "inspection could not determine the Java object return type." );
207
- }
208
- this .reportBuilder .addSkippedType (typeNameToString (outputType ));
199
+ addSkippedType (outputType , () -> "inspection could not determine the Java object return type." );
209
200
return ;
210
201
}
211
202
@@ -217,31 +208,34 @@ private GraphQLType unwrapIfNonNull(GraphQLType type) {
217
208
return (type instanceof GraphQLNonNull graphQLNonNull ? graphQLNonNull .getWrappedType () : type );
218
209
}
219
210
220
- private boolean isConnectionType (GraphQLType type ) {
211
+ private boolean isPaginatedType (GraphQLType type ) {
221
212
return (type instanceof GraphQLObjectType objectType &&
222
213
objectType .getName ().endsWith ("Connection" ) &&
223
214
objectType .getField ("edges" ) != null && objectType .getField ("pageInfo" ) != null );
224
215
}
225
216
226
- private GraphQLType getConnectionNodeType (GraphQLType type ) {
227
- String name = ((GraphQLObjectType ) type ).getName ();
228
- name = name .substring (0 , name .length () - 10 );
229
- type = this .schema .getType (name );
230
- Assert .state (type != null , "No '" + name + "' type" );
231
- return type ;
217
+ private GraphQLType getPaginatedType (GraphQLObjectType type ) {
218
+ String name = type .getName ().substring (0 , type .getName ().length () - 10 );
219
+ GraphQLType nodeType = this .schema .getType (name );
220
+ Assert .state (nodeType != null , "No node type for '" + type .getName () + "'" );
221
+ return nodeType ;
232
222
}
233
223
234
224
private ResolvableType nestForConnection (ResolvableType type ) {
235
225
type = nestIfReactive (type );
236
- Assert .state (type .hasGenerics (), "Expected type with generics: " + type );
226
+ if (logger .isDebugEnabled () && type .getGenerics ().length != 1 ) {
227
+ logger .debug ("Expected Connection type to have a generic parameter: " + type );
228
+ }
237
229
return type .getNested (2 );
238
230
}
239
231
240
232
private ResolvableType nestIfReactive (ResolvableType type ) {
241
233
Class <?> clazz = type .resolve (Object .class );
242
234
ReactiveAdapter adapter = this .reactiveAdapterRegistry .getAdapter (clazz );
243
235
if (adapter != null ) {
244
- Assert .state (!adapter .isNoValue (), "Expected value producing type: " + type );
236
+ if (logger .isDebugEnabled () && adapter .isNoValue ()) {
237
+ logger .debug ("Expected reactive/async return type that can produce value(s): " + type );
238
+ }
245
239
return type .getNested (2 );
246
240
}
247
241
return type ;
@@ -250,13 +244,17 @@ private ResolvableType nestIfReactive(ResolvableType type) {
250
244
private ResolvableType nestForList (ResolvableType type , boolean subscription ) {
251
245
ReactiveAdapter adapter = this .reactiveAdapterRegistry .getAdapter (type .resolve (Object .class ));
252
246
if (adapter != null ) {
253
- Assert .state (!adapter .isNoValue (), "Expected List compatible type: " + type );
247
+ if (logger .isDebugEnabled () && adapter .isNoValue ()) {
248
+ logger .debug ("Expected List compatible type: " + type );
249
+ }
254
250
type = type .getNested (2 );
255
251
if (adapter .isMultiValue () && !subscription ) {
256
252
return type ;
257
253
}
258
254
}
259
- Assert .state (type .isArray () || type .hasGenerics (), "Expected List compatible type: " + type );
255
+ if (logger .isDebugEnabled () && (!type .isArray () && type .getGenerics ().length != 1 )) {
256
+ logger .debug ("Expected List compatible type: " + type );
257
+ }
260
258
return type .getNested (2 );
261
259
}
262
260
@@ -283,6 +281,14 @@ private boolean hasProperty(ResolvableType resolvableType, String fieldName) {
283
281
}
284
282
}
285
283
284
+ private void addSkippedType (GraphQLType type , Supplier <String > reason ) {
285
+ String typeName = typeNameToString (type );
286
+ this .reportBuilder .addSkippedType (typeName );
287
+ if (logger .isDebugEnabled ()) {
288
+ logger .debug ("Skipped '" + typeName + "': " + reason .get ());
289
+ }
290
+ }
291
+
286
292
@ SuppressWarnings ("rawtypes" )
287
293
private void inspectDataFetcherRegistrations () {
288
294
this .runtimeWiring .getDataFetchers ().forEach ((typeName , registrations ) ->
0 commit comments