-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ValueToVariableValueCompilerTest.groovy
118 lines (100 loc) · 5 KB
/
ValueToVariableValueCompilerTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package graphql.normalized
import graphql.language.ArrayValue
import graphql.language.BooleanValue
import graphql.language.EnumValue
import graphql.language.FloatValue
import graphql.language.IntValue
import graphql.language.NullValue
import graphql.language.ObjectField
import graphql.language.ObjectValue
import graphql.language.StringValue
import graphql.schema.idl.TypeUtil
import spock.lang.Specification
class ValueToVariableValueCompilerTest extends Specification {
def "cam handle different ast Value objects"() {
expect:
def actual = ValueToVariableValueCompiler.normalisedValueToVariableValue(value)
actual == expected
where:
value | expected
NullValue.of() | null
IntValue.of(666) | 666
StringValue.of("str") | "str"
BooleanValue.of(true) | true
FloatValue.of(999d) | 999d
EnumValue.of("enumValue") | "enumValue"
ObjectValue.newObjectValue()
.objectField(ObjectField.newObjectField().name("a").value(IntValue.of(64)).build())
.objectField(ObjectField.newObjectField().name("b").value(StringValue.of("65")).build())
.build() | [a: 64, b: "65"]
ArrayValue.newArrayValue()
.value(IntValue.of(9))
.value(StringValue.of("10"))
.value(EnumValue.of("enum"))
.build() | [9, "10", "enum"]
}
def "can handle NormalizedInputValue values that are literals"() {
expect:
def niv = new NormalizedInputValue("TypeName", value)
def actual = ValueToVariableValueCompiler.normalisedValueToVariableValue(niv)
actual == expected
where:
value | expected
NullValue.of() | null
IntValue.of(666) | 666
StringValue.of("str") | "str"
BooleanValue.of(true) | true
FloatValue.of(999d) | 999d
EnumValue.of("enumValue") | "enumValue"
ObjectValue.newObjectValue()
.objectField(ObjectField.newObjectField().name("a").value(IntValue.of(64)).build())
.objectField(ObjectField.newObjectField().name("b").value(StringValue.of("65")).build())
.build() | [a: 64, b: "65"]
ArrayValue.newArrayValue()
.value(IntValue.of(9))
.value(StringValue.of("10"))
.value(EnumValue.of("enum"))
.build() | [9, "10", "enum"]
}
def "can handle NormalizedInputValue values that are not literals"() {
expect:
def niv = new NormalizedInputValue("TypeName", value)
def actual = ValueToVariableValueCompiler.normalisedValueToVariableValue(niv)
actual == expected
where:
value | expected
null | null
[IntValue.of(666), IntValue.of(664)] | [666, 664]
[a: IntValue.of(666), b: IntValue.of(664)] | [a: 666, b: 664]
// at present we dont handle straight up java objects like 123 because
// the ValueResolver never produces them during
// ValueResolver.getNormalizedVariableValues say - this is debatable behavior
// but for now this is what we do
}
def "can print variables as expected"() {
expect:
def niv = new NormalizedInputValue(typeName, value)
def actual = ValueToVariableValueCompiler.normalizedInputValueToVariable(niv, varCount)
actual.value == expectedValue
actual.variableReference.name == expectedVarName
actual.definition.name == expectedVarName
TypeUtil.simplePrint(actual.definition.type) == typeName
where:
value | varCount | typeName | expectedValue | expectedVarName
NullValue.newNullValue().build() | 1 | "ID" | null | "v1"
IntValue.of(666) | 2 | "Int!" | 666 | "v2"
StringValue.of("str") | 3 | "String" | "str" | "v3"
BooleanValue.of(true) | 4 | "Boolean!" | true | "v4"
FloatValue.of(999d) | 5 | "Float" | 999d | "v5"
EnumValue.of("enumValue") | 6 | "Foo!" | "enumValue" | "v6"
ObjectValue.newObjectValue()
.objectField(ObjectField.newObjectField().name("a").value(IntValue.of(64)).build())
.objectField(ObjectField.newObjectField().name("b").value(StringValue.of("65")).build())
.build() | 7 | "ObjectType" | [a: 64, b: "65"] | "v7"
ArrayValue.newArrayValue()
.value(IntValue.of(9))
.value(StringValue.of("10"))
.value(EnumValue.of("enum"))
.build() | 8 | "ArrayType" | [9, "10", "enum"] | "v8"
}
}