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 reactor .core .publisher .Mono ;
3135
3236import org .springframework .core .CoroutinesUtils ;
3337import org .springframework .core .KotlinDetector ;
34- import org .springframework .data .util .KotlinReflectionUtils ;
3538import org .springframework .graphql .execution .ContextPropagationHelper ;
3639import org .springframework .lang .Nullable ;
3740import org .springframework .util .Assert ;
@@ -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 @ Nullable
5257 private final Executor executor ;
@@ -137,6 +142,7 @@ protected Object doInvoke(GraphQLContext graphQLContext, Object... argValues) {
137142 private static Object invokeSuspendingFunction (Object bean , Method method , Object [] argValues ) {
138143 Object result = CoroutinesUtils .invokeSuspendingFunction (method , bean , argValues );
139144
145+ Assert .state (KOTLIN_REFLECT_PRESENT , "Missing org.jetbrains.kotlin:kotlin-reflect dependency" );
140146 // Support use of DataLoader from suspending function
141147 Class <?> returnType = KotlinReflectionUtils .getReturnType (method );
142148 if (CompletableFuture .class .isAssignableFrom (returnType )) {
@@ -210,4 +216,15 @@ protected Mono<Object[]> toArgsMono(Object[] args) {
210216 });
211217 }
212218
219+ static class KotlinReflectionUtils {
220+
221+ static Class <?> getReturnType (Method method ) {
222+ KFunction <?> kotlinFunction = ReflectJvmMapping .getKotlinFunction (method );
223+ if (kotlinFunction == null ) {
224+ throw new IllegalArgumentException (String .format ("Cannot resolve %s to a KFunction" , method ));
225+ }
226+ return JvmClassMappingKt .getJavaClass (KTypesJvm .getJvmErasure (kotlinFunction .getReturnType ()));
227+ }
228+ }
229+
213230}
0 commit comments