@@ -10,11 +10,101 @@ import org.junit.Test
10
10
import java.lang.reflect.InvocationHandler
11
11
import java.lang.reflect.Method
12
12
import java.lang.reflect.Proxy
13
+ import java.util.*
13
14
14
15
class MethodFieldResolverTest {
15
16
16
17
@Test
17
- fun shouldHandleScalarTypesAsMethodInputArgument () {
18
+ fun `should handle Optional type as method input argument` () {
19
+ val schema = SchemaParser .newParser()
20
+ .schemaString("""
21
+ type Query {
22
+ testValue(input: String): String
23
+ testOmitted(input: String): String
24
+ testNull(input: String): String
25
+ }
26
+ """
27
+ )
28
+ .scalars(customScalarType)
29
+ .resolvers(object : GraphQLQueryResolver {
30
+ fun testValue (input : Optional <String >) = input.toString()
31
+ fun testOmitted (input : Optional <String >) = input.toString()
32
+ fun testNull (input : Optional <String >) = input.toString()
33
+ })
34
+ .build()
35
+ .makeExecutableSchema()
36
+
37
+ val gql = GraphQL .newGraphQL(schema).build()
38
+
39
+ val result = gql
40
+ .execute(ExecutionInput .newExecutionInput()
41
+ .query("""
42
+ query {
43
+ testValue(input: "test-value")
44
+ testOmitted
45
+ testNull(input: null)
46
+ }
47
+ """ )
48
+ .context(Object ())
49
+ .root(Object ()))
50
+
51
+ val expected = mapOf (
52
+ " testValue" to " Optional[test-value]" ,
53
+ " testOmitted" to " Optional.empty" ,
54
+ " testNull" to " Optional.empty"
55
+ )
56
+
57
+ Assert .assertEquals(expected, result.getData())
58
+ }
59
+
60
+ @Test
61
+ fun `should handle Optional type as method input argument with omission detection` () {
62
+ val schema = SchemaParser .newParser()
63
+ .schemaString("""
64
+ type Query {
65
+ testValue(input: String): String
66
+ testOmitted(input: String): String
67
+ testNull(input: String): String
68
+ }
69
+ """
70
+ )
71
+ .scalars(customScalarType)
72
+ .resolvers(object : GraphQLQueryResolver {
73
+ fun testValue (input : Optional <String >) = input.toString()
74
+ fun testOmitted (input : Optional <String >? ) = input.toString()
75
+ fun testNull (input : Optional <String >) = input.toString()
76
+ })
77
+ .options(SchemaParserOptions .newOptions()
78
+ .inputArgumentOptionalDetectOmission(true )
79
+ .build())
80
+ .build()
81
+ .makeExecutableSchema()
82
+
83
+ val gql = GraphQL .newGraphQL(schema).build()
84
+
85
+ val result = gql
86
+ .execute(ExecutionInput .newExecutionInput()
87
+ .query("""
88
+ query {
89
+ testValue(input: "test-value")
90
+ testOmitted
91
+ testNull(input: null)
92
+ }
93
+ """ )
94
+ .context(Object ())
95
+ .root(Object ()))
96
+
97
+ val expected = mapOf (
98
+ " testValue" to " Optional[test-value]" ,
99
+ " testOmitted" to " null" ,
100
+ " testNull" to " Optional.empty"
101
+ )
102
+
103
+ Assert .assertEquals(expected, result.getData())
104
+ }
105
+
106
+ @Test
107
+ fun `should handle scalar types as method input argument` () {
18
108
val schema = SchemaParser .newParser()
19
109
.schemaString("""
20
110
scalar CustomScalar
@@ -47,7 +137,7 @@ class MethodFieldResolverTest {
47
137
}
48
138
49
139
@Test
50
- fun shouldHandleListsOfScalarTypes () {
140
+ fun `should handle lists of scalar types` () {
51
141
val schema = SchemaParser .newParser()
52
142
.schemaString("""
53
143
scalar CustomScalar
@@ -80,7 +170,7 @@ class MethodFieldResolverTest {
80
170
}
81
171
82
172
@Test
83
- fun shouldHandleProxies () {
173
+ fun `should handle proxies` () {
84
174
val invocationHandler = object : InvocationHandler {
85
175
override fun invoke (proxy : Any , method : Method , args : Array <out Any >): Any {
86
176
return when (method.name) {
0 commit comments