Skip to content

Commit

Permalink
Merge branch 'master' into kotlin-1.9.20
Browse files Browse the repository at this point in the history
  • Loading branch information
kilink authored Nov 7, 2023
2 parents 68055a1 + 645bc66 commit 544126b
Show file tree
Hide file tree
Showing 2 changed files with 40 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
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,43 @@ internal class InputArgumentTest {
}
}

@Test
fun `The enum scalar in a non-nested input should be mapped`() {
val schema = """
type Query {
hello(countryCode: CountryCode): String
}
scalar CountryCode
""".trimIndent()

@DgsComponent
class Fetcher {
@DgsData(parentType = "Query", field = "hello")
fun hello(@InputArgument countryCode: CountryCode): String {
assertThat(countryCode).isInstanceOf(CountryCode::class.java)
assertThat(countryCode).isEqualTo(CountryCode.ZW)
return "Hello, this is a $countryCode greeting"
}

@DgsRuntimeWiring
fun addScalar(builder: RuntimeWiring.Builder): RuntimeWiring.Builder {
return builder.scalar(ExtendedScalars.CountryCode)
}
}

contextRunner.withBeans(Fetcher::class).run { context ->
val provider = schemaProvider(context)
val build = GraphQL.newGraphQL(provider.schema(schema)).build()
val executionResult = build.execute("""{hello(countryCode: "ZW")}""")
assertThat(executionResult).isNotNull
assertThat(executionResult.errors).isEmpty()
assertThat(executionResult.isDataPresent).isTrue
val data = executionResult.getData<Map<String, *>>()
assertThat(data).extracting("hello").isEqualTo("Hello, this is a ZW greeting")
}
}

private fun ApplicationContextRunner.withBeans(vararg beanClasses: KClass<*>): ApplicationContextRunner {
var context = this
for (klazz in beanClasses) {
Expand Down

0 comments on commit 544126b

Please sign in to comment.