-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
GraphQLInputObjectFieldTest.groovy
102 lines (86 loc) · 3.7 KB
/
GraphQLInputObjectFieldTest.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
package graphql.schema
import graphql.introspection.Introspection
import graphql.language.FloatValue
import spock.lang.Specification
import static graphql.Scalars.GraphQLFloat
import static graphql.Scalars.GraphQLInt
import static graphql.schema.GraphQLInputObjectField.newInputObjectField
import static graphql.TestUtil.mkDirective
class GraphQLInputObjectFieldTest extends Specification {
def "object can be transformed"() {
given:
def startingField = newInputObjectField()
.name("F1")
.type(GraphQLFloat)
.description("F1_description")
.withDirective(mkDirective("directive1", Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION))
.withDirective(mkDirective("directive2", Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION))
.deprecate("No longer useful")
.build()
when:
def transformedField = startingField.transform({ builder ->
builder.name("F2")
.type(GraphQLInt)
.deprecate(null)
.withDirective(mkDirective("directive3", Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION))
})
then:
startingField.name == "F1"
startingField.type == GraphQLFloat
startingField.description == "F1_description"
startingField.isDeprecated()
startingField.getDeprecationReason() == "No longer useful"
startingField.getDirectives().size() == 2
startingField.getDirective("directive1") != null
startingField.getDirective("directive2") != null
transformedField.name == "F2"
transformedField.type == GraphQLInt
transformedField.description == "F1_description" // left alone
!transformedField.isDeprecated()
transformedField.getDeprecationReason() == null
transformedField.getDirectives().size() == 3
transformedField.getDirective("directive1") != null
transformedField.getDirective("directive2") != null
transformedField.getDirective("directive3") != null
}
def "can get default values statically"() {
when:
def startingField = newInputObjectField()
.name("F1")
.type(GraphQLFloat)
.description("F1_description")
.defaultValueProgrammatic(1.23d)
.build()
def inputValue = startingField.getInputFieldDefaultValue()
def resolvedValue = GraphQLInputObjectField.getInputFieldDefaultValue(startingField)
then:
inputValue.isExternal()
inputValue.getValue() == 1.23d
resolvedValue == 1.23d
when:
startingField = newInputObjectField()
.name("F1")
.type(GraphQLFloat)
.description("F1_description")
.defaultValueLiteral(FloatValue.newFloatValue().value(1.23d).build())
.build()
inputValue = startingField.getInputFieldDefaultValue()
resolvedValue = GraphQLInputObjectField.getInputFieldDefaultValue(startingField)
then:
inputValue.isLiteral()
(inputValue.getValue() as FloatValue).getValue().toDouble() == 1.23d
resolvedValue == 1.23d
when: " we have no values "
startingField = newInputObjectField()
.name("F1")
.type(GraphQLFloat)
.description("F1_description")
.build()
inputValue = startingField.getInputFieldDefaultValue()
resolvedValue = GraphQLInputObjectField.getInputFieldDefaultValue(startingField)
then:
inputValue.isNotSet()
inputValue.getValue() == null
resolvedValue == null
}
}