@@ -20,6 +20,7 @@ import com.netflix.graphql.dgs.DgsComponent
20
20
import com.netflix.graphql.dgs.DgsData
21
21
import com.netflix.graphql.dgs.DgsQuery
22
22
import com.netflix.graphql.dgs.DgsRuntimeWiring
23
+ import com.netflix.graphql.dgs.DgsScalar
23
24
import com.netflix.graphql.dgs.InputArgument
24
25
import com.netflix.graphql.dgs.LocalDateTimeScalar
25
26
import com.netflix.graphql.dgs.exceptions.DataFetcherInputArgumentSchemaMismatchException
@@ -49,8 +50,12 @@ import com.netflix.graphql.dgs.scalars.UploadScalar
49
50
import graphql.ExceptionWhileDataFetching
50
51
import graphql.ExecutionInput
51
52
import graphql.GraphQL
53
+ import graphql.GraphQLContext
54
+ import graphql.execution.CoercedVariables
55
+ import graphql.language.StringValue
52
56
import graphql.scalars.ExtendedScalars
53
57
import graphql.scalars.country.code.CountryCode
58
+ import graphql.schema.Coercing
54
59
import graphql.schema.DataFetchingEnvironment
55
60
import graphql.schema.idl.RuntimeWiring
56
61
import org.assertj.core.api.Assertions.LIST
@@ -67,6 +72,7 @@ import org.springframework.mock.web.MockMultipartFile
67
72
import org.springframework.web.multipart.MultipartFile
68
73
import java.time.LocalDateTime
69
74
import java.time.format.DateTimeFormatter
75
+ import java.util.Locale
70
76
import java.util.Optional
71
77
import kotlin.reflect.KClass
72
78
@@ -2297,6 +2303,56 @@ internal class InputArgumentTest {
2297
2303
}
2298
2304
}
2299
2305
2306
+ @JvmInline value class ValueClass (val value : String ) {
2307
+ override fun toString (): String {
2308
+ return value
2309
+ }
2310
+ }
2311
+
2312
+ @Test
2313
+ fun `@InputArgument mapping works for kotlin value class parameters` () {
2314
+ @DgsComponent
2315
+ class Component {
2316
+ @DgsQuery(field = " foo" )
2317
+ fun fooFetcher (@InputArgument input : ValueClass ): String {
2318
+ return input.toString()
2319
+ }
2320
+ }
2321
+
2322
+ @DgsScalar(name = " Value" )
2323
+ class ValueScalar : Coercing <ValueClass , String > {
2324
+ override fun parseValue (input : Any , graphQLContext : GraphQLContext , locale : Locale ): ValueClass {
2325
+ return ValueClass (input.toString())
2326
+ }
2327
+
2328
+ override fun parseLiteral (
2329
+ input : graphql.language.Value <* >,
2330
+ variables : CoercedVariables ,
2331
+ graphQLContext : GraphQLContext ,
2332
+ locale : Locale
2333
+ ): ValueClass {
2334
+ return ValueClass ((input as StringValue ).value)
2335
+ }
2336
+ }
2337
+
2338
+ contextRunner.withBeans(Component ::class , ValueScalar ::class ).run { applicationContext ->
2339
+ val schemaProvider = schemaProvider(applicationContext = applicationContext)
2340
+ val schema = schemaProvider.schema(
2341
+ """
2342
+ scalar Value
2343
+ type Query {
2344
+ foo(input: Value!): String!
2345
+ }
2346
+ """ .trimIndent()
2347
+ ).graphQLSchema
2348
+
2349
+ val graphql = GraphQL .newGraphQL(schema).build()
2350
+ val result = graphql.execute(" { foo(input: \" input-value\" ) }" )
2351
+ assertThat(result.errors).isEmpty()
2352
+ assertThat(result.getData<Map <String , String >>()).containsEntry(" foo" , " input-value" )
2353
+ }
2354
+ }
2355
+
2300
2356
private fun ApplicationContextRunner.withBeans (vararg beanClasses : KClass <* >): ApplicationContextRunner {
2301
2357
var context = this
2302
2358
for (klazz in beanClasses) {
0 commit comments