1
1
package graphql.kickstart.tools
2
2
3
+ import graphql.GraphQLContext
4
+ import graphql.execution.CoercedVariables
3
5
import graphql.execution.DataFetcherResult
4
6
import graphql.language.ObjectValue
5
7
import graphql.language.StringValue
8
+ import graphql.language.Value
6
9
import graphql.schema.*
7
10
import kotlinx.coroutines.CompletableDeferred
8
11
import kotlinx.coroutines.channels.Channel
@@ -444,18 +447,22 @@ val customScalarId = GraphQLScalarType.newScalar()
444
447
.name(" ID" )
445
448
.description(" Overrides built-in ID" )
446
449
.coercing(object : Coercing <UUID , String > {
447
- override fun serialize (input : Any ): String? = when (input) {
450
+ override fun serialize (input : Any , context : GraphQLContext , locale : Locale ) = when (input) {
448
451
is String -> input
449
452
is UUID -> input.toString()
450
453
else -> null
451
454
}
452
455
453
- override fun parseValue (input : Any ): UUID = parseLiteral(input)
454
-
455
- override fun parseLiteral (input : Any ): UUID = when (input) {
456
+ override fun parseValue (input : Any , context : GraphQLContext , locale : Locale ) = when (input) {
456
457
is StringValue -> UUID .fromString(input.value)
457
458
else -> throw CoercingParseLiteralException ()
458
459
}
460
+
461
+ override fun parseLiteral (input : Value <* >, variables : CoercedVariables , context : GraphQLContext , locale : Locale ) =
462
+ when (input) {
463
+ is StringValue -> UUID .fromString(input.value)
464
+ else -> throw CoercingParseLiteralException ()
465
+ }
459
466
})
460
467
.build()
461
468
@@ -464,18 +471,22 @@ val customScalarUUID = GraphQLScalarType.newScalar()
464
471
.description(" UUID" )
465
472
.coercing(object : Coercing <UUID , String > {
466
473
467
- override fun serialize (input : Any ): String? = when (input) {
474
+ override fun serialize (input : Any , context : GraphQLContext , locale : Locale ): String? = when (input) {
468
475
is String -> input
469
476
is UUID -> input.toString()
470
477
else -> null
471
478
}
472
479
473
- override fun parseValue (input : Any ): UUID = parseLiteral(input)
474
-
475
- override fun parseLiteral (input : Any ): UUID = when (input) {
480
+ override fun parseValue (input : Any , context : GraphQLContext , locale : Locale ): UUID = when (input) {
476
481
is StringValue -> UUID .fromString(input.value)
477
482
else -> throw CoercingParseLiteralException ()
478
483
}
484
+
485
+ override fun parseLiteral (input : Value <* >, variables : CoercedVariables , context : GraphQLContext , locale : Locale ): UUID =
486
+ when (input) {
487
+ is StringValue -> UUID .fromString(input.value)
488
+ else -> throw CoercingParseLiteralException ()
489
+ }
479
490
})
480
491
.build()
481
492
@@ -485,12 +496,19 @@ val customScalarMap = GraphQLScalarType.newScalar()
485
496
.coercing(object : Coercing <Map <String , Any >, Map <String , Any >> {
486
497
487
498
@Suppress(" UNCHECKED_CAST" )
488
- override fun parseValue (input : Any ): Map <String , Any > = input as Map <String , Any >
499
+ override fun parseValue (input : Any , context : GraphQLContext , locale : Locale ): Map <String , Any > = input as Map <String , Any >
489
500
490
501
@Suppress(" UNCHECKED_CAST" )
491
- override fun serialize (dataFetcherResult : Any ): Map <String , Any > = dataFetcherResult as Map <String , Any >
492
-
493
- override fun parseLiteral (input : Any ): Map <String , Any > = (input as ObjectValue ).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue ).value }
502
+ override fun serialize (dataFetcherResult : Any , context : GraphQLContext , locale : Locale ): Map <String , Any > =
503
+ dataFetcherResult as Map <String , Any >
504
+
505
+ override fun parseLiteral (
506
+ input : Value <* >,
507
+ variables : CoercedVariables ,
508
+ context : GraphQLContext ,
509
+ locale : Locale
510
+ ): Map <String , Any > =
511
+ (input as ObjectValue ).objectFields.associateBy { it.name }.mapValues { (it.value.value as StringValue ).value }
494
512
})
495
513
.build()
496
514
@@ -499,11 +517,11 @@ val uploadScalar: GraphQLScalarType = GraphQLScalarType.newScalar()
499
517
.name(" Upload" )
500
518
.description(" A file part in a multipart request" )
501
519
.coercing(object : Coercing <Part ?, Void ?> {
502
- override fun serialize (dataFetcherResult : Any ): Void ? {
520
+ override fun serialize (dataFetcherResult : Any , context : GraphQLContext , locale : Locale ): Void ? {
503
521
throw CoercingSerializeException (" Upload is an input-only type" )
504
522
}
505
523
506
- override fun parseValue (input : Any ): Part {
524
+ override fun parseValue (input : Any , context : GraphQLContext , locale : Locale ): Part {
507
525
return when (input) {
508
526
is Part -> {
509
527
input
@@ -514,9 +532,8 @@ val uploadScalar: GraphQLScalarType = GraphQLScalarType.newScalar()
514
532
}
515
533
}
516
534
517
- override fun parseLiteral (input : Any ): Part {
518
- throw CoercingParseLiteralException (
519
- " Must use variables to specify Upload values" )
535
+ override fun parseLiteral (input : Value <* >, variables : CoercedVariables , context : GraphQLContext , locale : Locale ): Part {
536
+ throw CoercingParseLiteralException (" Must use variables to specify Upload values" )
520
537
}
521
538
}).build()
522
539
0 commit comments