|
45 | 45 | import graphql.schema.GraphQLCodeRegistry; |
46 | 46 | import graphql.schema.idl.RuntimeWiring; |
47 | 47 | import graphql.schema.idl.TypeDefinitionRegistry; |
48 | | -import kotlin.jvm.JvmClassMappingKt; |
49 | | -import kotlin.reflect.KFunction; |
50 | | -import kotlin.reflect.KType; |
51 | | -import kotlin.reflect.full.KClassifiers; |
52 | | -import kotlin.reflect.full.KTypes; |
53 | | -import kotlin.reflect.jvm.ReflectJvmMapping; |
54 | | -import kotlinx.coroutines.flow.Flow; |
55 | 48 | import org.dataloader.DataLoader; |
56 | 49 | import org.reactivestreams.Publisher; |
57 | 50 | import reactor.core.publisher.Flux; |
|
64 | 57 | import org.springframework.core.KotlinDetector; |
65 | 58 | import org.springframework.core.MethodParameter; |
66 | 59 | import org.springframework.core.ParameterNameDiscoverer; |
| 60 | +import org.springframework.core.ReactiveAdapter; |
| 61 | +import org.springframework.core.ReactiveAdapterRegistry; |
67 | 62 | import org.springframework.core.ResolvableType; |
68 | 63 | import org.springframework.core.annotation.AnnotatedElementUtils; |
69 | 64 | import org.springframework.data.domain.ScrollPosition; |
@@ -384,15 +379,15 @@ private DataFetcher<Object> registerBatchLoader(DataFetcherMappingInfo info) { |
384 | 379 | clazz = returnType.getNestedParameterType(); |
385 | 380 | } |
386 | 381 |
|
387 | | - if (clazz.equals(Flux.class) || Collection.class.isAssignableFrom(clazz) || |
388 | | - (KotlinDetector.isSuspendingFunction(method) && KotlinDelegate.isFlowReturnType(method))) { |
| 382 | + ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(clazz); |
389 | 383 |
|
| 384 | + if (Collection.class.isAssignableFrom(clazz) || (adapter != null && adapter.isMultiValue())) { |
390 | 385 | registration.registerBatchLoader(invocable::invokeForIterable); |
391 | 386 | ResolvableType valueType = ResolvableType.forMethodParameter(returnType.nested()); |
392 | 387 | return new BatchMappingDataFetcher(info, valueType, dataLoaderKey); |
393 | 388 | } |
394 | 389 |
|
395 | | - if (clazz.equals(Mono.class)) { |
| 390 | + if (adapter != null) { |
396 | 391 | returnType = returnType.nested(); |
397 | 392 | clazz = returnType.getNestedParameterType(); |
398 | 393 | } |
@@ -672,20 +667,4 @@ Set<DataFetcherMappingInfo> removeExplicitMappings( |
672 | 667 | } |
673 | 668 | } |
674 | 669 |
|
675 | | - |
676 | | - /** |
677 | | - * Inner class to avoid a hard dependency on Kotlin at runtime. |
678 | | - */ |
679 | | - private static final class KotlinDelegate { |
680 | | - |
681 | | - private static final KType flowType = |
682 | | - KClassifiers.getStarProjectedType(JvmClassMappingKt.getKotlinClass(Flow.class)); |
683 | | - |
684 | | - static boolean isFlowReturnType(Method method) { |
685 | | - KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method); |
686 | | - return (function != null && KTypes.isSubtypeOf(function.getReturnType(), flowType)); |
687 | | - } |
688 | | - |
689 | | - } |
690 | | - |
691 | 670 | } |
0 commit comments