33
33
34
34
import org .springframework .context .ApplicationContext ;
35
35
import org .springframework .core .ExceptionDepthComparator ;
36
+ import org .springframework .core .KotlinDetector ;
36
37
import org .springframework .core .MethodIntrospector ;
37
38
import org .springframework .core .MethodParameter ;
38
39
import org .springframework .core .annotation .AnnotatedElementUtils ;
@@ -370,7 +371,11 @@ private interface ReturnValueAdapter {
370
371
*/
371
372
static ReturnValueAdapter createFor (MethodParameter returnType ) {
372
373
Class <?> parameterType = returnType .getParameterType ();
373
- if (parameterType == void .class ) {
374
+ Method method = returnType .getMethod ();
375
+ if (method != null && KotlinDetector .isSuspendingFunction (method )) {
376
+ return createForMono (returnType );
377
+ }
378
+ else if (parameterType == void .class ) {
374
379
return forVoid ;
375
380
}
376
381
else if (parameterType .equals (GraphQLError .class )) {
@@ -382,18 +387,7 @@ else if (Collection.class.isAssignableFrom(parameterType)) {
382
387
}
383
388
}
384
389
else if (Mono .class .isAssignableFrom (parameterType )) {
385
- returnType = returnType .nested ();
386
- Class <?> nestedType = returnType .getNestedParameterType ();
387
- if (nestedType == Void .class ) {
388
- return forMonoVoid ;
389
- }
390
- if (Collection .class .isAssignableFrom (nestedType )) {
391
- returnType = returnType .nested ();
392
- nestedType = returnType .getNestedParameterType ();
393
- }
394
- if (nestedType .equals (GraphQLError .class ) || nestedType .equals (Object .class )) {
395
- return forMono ;
396
- }
390
+ return createForMono (returnType .nested ());
397
391
}
398
392
else if (parameterType .equals (Object .class )) {
399
393
return forObject ;
@@ -402,6 +396,23 @@ else if (parameterType.equals(Object.class)) {
402
396
"Invalid return type for @GraphQlExceptionHandler method: " + returnType );
403
397
}
404
398
399
+ private static ReturnValueAdapter createForMono (MethodParameter returnType ) {
400
+ Class <?> nestedType = returnType .getNestedParameterType ();
401
+ if (nestedType == Void .class ) {
402
+ return forMonoVoid ;
403
+ }
404
+ if (Collection .class .isAssignableFrom (nestedType )) {
405
+ returnType = returnType .nested ();
406
+ nestedType = returnType .getNestedParameterType ();
407
+ }
408
+ if (nestedType .equals (GraphQLError .class ) || nestedType .equals (Object .class )) {
409
+ return forMono ;
410
+ }
411
+ throw new IllegalStateException (
412
+ "Invalid return type for @GraphQlExceptionHandler method: " + returnType );
413
+ }
414
+
415
+
405
416
/** Adapter for void */
406
417
ReturnValueAdapter forVoid = (result , returnType , ex ) -> Mono .just (Collections .emptyList ());
407
418
0 commit comments