@@ -18,18 +18,26 @@ package nl.nlportal.graphql.customtype
18
18
import com.fasterxml.jackson.databind.JsonNode
19
19
import com.fasterxml.jackson.databind.node.JsonNodeFactory
20
20
import com.fasterxml.jackson.databind.node.ObjectNode
21
- import nl.nlportal.core.util.Mapper
21
+ import graphql.GraphQLContext
22
+ import graphql.execution.CoercedVariables
22
23
import graphql.language.IntValue
23
24
import graphql.language.ObjectField
24
25
import graphql.language.ObjectValue
25
26
import graphql.language.StringValue
27
+ import graphql.language.Value
26
28
import graphql.schema.Coercing
27
29
import graphql.schema.CoercingParseLiteralException
28
30
import graphql.schema.CoercingSerializeException
29
31
import graphql.schema.GraphQLScalarType
32
+ import nl.nlportal.core.util.Mapper
33
+ import java.util.Locale
30
34
31
35
object JSONCoercing : Coercing<ObjectNode, ObjectNode> {
32
- override fun parseValue (input : Any ): ObjectNode {
36
+ override fun parseValue (
37
+ input : Any ,
38
+ graphQLContext : GraphQLContext ,
39
+ locale : Locale ,
40
+ ): ObjectNode {
33
41
if (input is ObjectValue ) {
34
42
val jsonNode: ObjectNode = JsonNodeFactory .instance.objectNode()
35
43
for (f: ObjectField in input.objectFields) {
@@ -42,16 +50,25 @@ object JSONCoercing : Coercing<ObjectNode, ObjectNode> {
42
50
throw CoercingParseLiteralException (" Expected valid JSON input but was $input " )
43
51
}
44
52
45
- override fun parseLiteral (input : Any ): ObjectNode {
53
+ override fun parseLiteral (
54
+ input : Value <* >,
55
+ variables : CoercedVariables ,
56
+ graphQLContext : GraphQLContext ,
57
+ locale : Locale ,
58
+ ): ObjectNode {
46
59
val jsonString = (input as ? ObjectValue )!!
47
60
return runCatching {
48
- parseValue(input)
61
+ parseValue(input, graphQLContext, locale )
49
62
}.getOrElse {
50
63
throw CoercingParseLiteralException (" Expected valid JSON literal but was $jsonString " )
51
64
}
52
65
}
53
66
54
- override fun serialize (dataFetcherResult : Any ): ObjectNode =
67
+ override fun serialize (
68
+ dataFetcherResult : Any ,
69
+ graphQLContext : GraphQLContext ,
70
+ locale : Locale ,
71
+ ): ObjectNode =
55
72
runCatching {
56
73
Mapper .get().readValue(dataFetcherResult.toString(), ObjectNode ::class .java)
57
74
}.getOrElse {
0 commit comments