2727
2828import graphql .GraphQLContext ;
2929import io .micrometer .context .ContextSnapshot ;
30+ import kotlin .jvm .JvmClassMappingKt ;
31+ import kotlin .reflect .KFunction ;
32+ import kotlin .reflect .jvm .KTypesJvm ;
33+ import kotlin .reflect .jvm .ReflectJvmMapping ;
3034import org .jspecify .annotations .Nullable ;
3135import reactor .core .publisher .Mono ;
3236
3337import org .springframework .core .CoroutinesUtils ;
3438import org .springframework .core .KotlinDetector ;
35- import org .springframework .data .util .KotlinReflectionUtils ;
3639import org .springframework .graphql .execution .ContextPropagationHelper ;
3740import org .springframework .util .Assert ;
3841
@@ -47,6 +50,8 @@ public abstract class InvocableHandlerMethodSupport extends HandlerMethod {
4750
4851 private static final Object NO_VALUE = new Object ();
4952
53+ private static final boolean KOTLIN_REFLECT_PRESENT = KotlinDetector .isKotlinReflectPresent ();
54+
5055
5156 private final @ Nullable Executor executor ;
5257
@@ -135,6 +140,7 @@ protected InvocableHandlerMethodSupport(
135140 private static Object invokeSuspendingFunction (Object bean , Method method , @ Nullable Object [] argValues ) {
136141 Object result = CoroutinesUtils .invokeSuspendingFunction (method , bean , argValues );
137142
143+ Assert .state (KOTLIN_REFLECT_PRESENT , "Missing org.jetbrains.kotlin:kotlin-reflect dependency" );
138144 // Support use of DataLoader from suspending function
139145 Class <?> returnType = KotlinReflectionUtils .getReturnType (method );
140146 if (CompletableFuture .class .isAssignableFrom (returnType )) {
@@ -209,4 +215,15 @@ private Throwable processInvocationTargetException(@Nullable Object[] argValues,
209215 });
210216 }
211217
218+ static class KotlinReflectionUtils {
219+
220+ static Class <?> getReturnType (Method method ) {
221+ KFunction <?> kotlinFunction = ReflectJvmMapping .getKotlinFunction (method );
222+ if (kotlinFunction == null ) {
223+ throw new IllegalArgumentException (String .format ("Cannot resolve %s to a KFunction" , method ));
224+ }
225+ return JvmClassMappingKt .getJavaClass (KTypesJvm .getJvmErasure (kotlinFunction .getReturnType ()));
226+ }
227+ }
228+
212229}
0 commit comments