Skip to content

Commit

Permalink
Use KotlinDetector in DataFetcherInvoker
Browse files Browse the repository at this point in the history
Use KotlinDetector from Spring in DataFetcherInvoker, and do the detection once
in the field initialization.
  • Loading branch information
kilink committed Nov 7, 2023
1 parent d6d57fd commit 645bc66
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import graphql.schema.DataFetchingEnvironment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.reactor.mono
import org.springframework.core.BridgeMethodResolver
import org.springframework.core.KotlinDetector
import org.springframework.core.MethodParameter
import org.springframework.core.ParameterNameDiscoverer
import org.springframework.core.annotation.SynthesizingMethodParameter
Expand All @@ -44,7 +45,7 @@ class DataFetcherInvoker internal constructor(
) : DataFetcher<Any?> {

private val bridgedMethod: Method = BridgeMethodResolver.findBridgedMethod(method)
private val kotlinFunction: KFunction<*>? = bridgedMethod.kotlinFunction
private val kotlinFunction: KFunction<*>? = if (KotlinDetector.isKotlinType(bridgedMethod.declaringClass)) bridgedMethod.kotlinFunction else null
private val completableFutureWrapper = CompletableFutureWrapper(taskExecutor)

private val methodParameters: List<MethodParameter> = bridgedMethod.parameters.map { parameter ->
Expand All @@ -65,7 +66,7 @@ class DataFetcherInvoker internal constructor(
return ReflectionUtils.invokeMethod(bridgedMethod, dgsComponent)
}

if (dgsComponent.javaClass.getDeclaredAnnotation(Metadata::class.java) != null && kotlinFunction != null) {
if (kotlinFunction != null) {
return invokeKotlinMethod(kotlinFunction, environment)
}

Expand Down

0 comments on commit 645bc66

Please sign in to comment.