26
26
27
27
import graphql .GraphQLContext ;
28
28
import io .micrometer .context .ContextSnapshot ;
29
- import org .springframework .data .util .KotlinReflectionUtils ;
30
29
import reactor .core .publisher .Mono ;
31
30
32
31
import org .springframework .core .CoroutinesUtils ;
33
32
import org .springframework .core .KotlinDetector ;
33
+ import org .springframework .data .util .KotlinReflectionUtils ;
34
34
import org .springframework .lang .Nullable ;
35
35
import org .springframework .util .Assert ;
36
36
@@ -82,18 +82,7 @@ protected Object doInvoke(GraphQLContext graphQLContext, Object... argValues) {
82
82
Method method = getBridgedMethod ();
83
83
try {
84
84
if (KotlinDetector .isSuspendingFunction (method )) {
85
- Object result = CoroutinesUtils .invokeSuspendingFunction (method , getBean (), argValues );
86
-
87
- Class <?> returnType = KotlinReflectionUtils .getReturnType (method );
88
-
89
- if (CompletableFuture .class .isAssignableFrom (returnType )) {
90
- @ SuppressWarnings ("unchecked" )
91
- Mono <CompletableFuture <?>> mono = (Mono <CompletableFuture <?>>)result ;
92
- // Unwrap nested CompletableFuture
93
- return mono .flatMap (Mono ::fromFuture );
94
- }
95
-
96
- return result ;
85
+ return invokeSuspendingFunction (getBean (), method , argValues );
97
86
}
98
87
Object result = method .invoke (getBean (), argValues );
99
88
return handleReturnValue (graphQLContext , result );
@@ -119,6 +108,19 @@ protected Object doInvoke(GraphQLContext graphQLContext, Object... argValues) {
119
108
}
120
109
}
121
110
111
+ @ SuppressWarnings ({"ReactiveStreamsUnusedPublisher" , "unchecked" })
112
+ private static Object invokeSuspendingFunction (Object bean , Method method , Object [] argValues ) {
113
+ Object result = CoroutinesUtils .invokeSuspendingFunction (method , bean , argValues );
114
+
115
+ // Support DataLoader use
116
+ Class <?> returnType = KotlinReflectionUtils .getReturnType (method );
117
+ if (CompletableFuture .class .isAssignableFrom (returnType )) {
118
+ return ((Mono <CompletableFuture <?>>) result ).flatMap (Mono ::fromFuture );
119
+ }
120
+
121
+ return result ;
122
+ }
123
+
122
124
@ Nullable
123
125
@ SuppressWarnings ("deprecation" )
124
126
private Object handleReturnValue (GraphQLContext graphQLContext , @ Nullable Object result ) {
0 commit comments