-
Notifications
You must be signed in to change notification settings - Fork 1
/
rules_possible_fragment_spreads_test.go
182 lines (174 loc) · 8.21 KB
/
rules_possible_fragment_spreads_test.go
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package graphql_test
import (
"testing"
"github.com/sprucehealth/graphql"
"github.com/sprucehealth/graphql/gqlerrors"
"github.com/sprucehealth/graphql/testutil"
)
func TestValidate_PossibleFragmentSpreads_OfTheSameObject(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment objectWithinObject on Dog { ...dogFragment }
fragment dogFragment on Dog { barkVolume }
`)
}
func TestValidate_PossibleFragmentSpreads_OfTheSameObjectWithInlineFragment(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment objectWithinObjectAnon on Dog { ... on Dog { barkVolume } }
`)
}
func TestValidate_PossibleFragmentSpreads_ObjectIntoAnImplementedInterface(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment objectWithinInterface on Pet { ...dogFragment }
fragment dogFragment on Dog { barkVolume }
`)
}
func TestValidate_PossibleFragmentSpreads_ObjectIntoContainingUnion(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment objectWithinUnion on CatOrDog { ...dogFragment }
fragment dogFragment on Dog { barkVolume }
`)
}
func TestValidate_PossibleFragmentSpreads_UnionIntoContainedObject(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment unionWithinObject on Dog { ...catOrDogFragment }
fragment catOrDogFragment on CatOrDog { __typename }
`)
}
func TestValidate_PossibleFragmentSpreads_UnionIntoOverlappingInterface(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment unionWithinInterface on Pet { ...catOrDogFragment }
fragment catOrDogFragment on CatOrDog { __typename }
`)
}
func TestValidate_PossibleFragmentSpreads_UnionIntoOverlappingUnion(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment unionWithinUnion on DogOrHuman { ...catOrDogFragment }
fragment catOrDogFragment on CatOrDog { __typename }
`)
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoImplementedObject(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment interfaceWithinObject on Dog { ...petFragment }
fragment petFragment on Pet { name }
`)
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoOverlappingInterface(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment interfaceWithinInterface on Pet { ...beingFragment }
fragment beingFragment on Being { name }
`)
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoOverlappingInterfaceInInlineFragment(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment interfaceWithinInterface on Pet { ... on Being { name } }
`)
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoOverlappingUnion(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment interfaceWithinUnion on CatOrDog { ...petFragment }
fragment petFragment on Pet { name }
`)
}
func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObject(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidObjectWithinObject on Cat { ...dogFragment }
fragment dogFragment on Dog { barkVolume }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "dogFragment" cannot be spread here as objects of `+
`type "Cat" can never be of type "Dog".`, 2, 51),
})
}
func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObjectInInlineFragment(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidObjectWithinObjectAnon on Cat {
... on Dog { barkVolume }
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment cannot be spread here as objects of `+
`type "Cat" can never be of type "Dog".`, 3, 9),
})
}
func TestValidate_PossibleFragmentSpreads_ObjectIntoNotImplementingInterface(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidObjectWithinInterface on Pet { ...humanFragment }
fragment humanFragment on Human { pets { name } }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "humanFragment" cannot be spread here as objects of `+
`type "Pet" can never be of type "Human".`, 2, 54),
})
}
func TestValidate_PossibleFragmentSpreads_ObjectIntoNotContainingUnion(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidObjectWithinUnion on CatOrDog { ...humanFragment }
fragment humanFragment on Human { pets { name } }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "humanFragment" cannot be spread here as objects of `+
`type "CatOrDog" can never be of type "Human".`, 2, 55),
})
}
func TestValidate_PossibleFragmentSpreads_UnionIntoNotContainedObject(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidUnionWithinObject on Human { ...catOrDogFragment }
fragment catOrDogFragment on CatOrDog { __typename }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "catOrDogFragment" cannot be spread here as objects of `+
`type "Human" can never be of type "CatOrDog".`, 2, 52),
})
}
func TestValidate_PossibleFragmentSpreads_UnionIntoNonOverlappingInterface(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidUnionWithinInterface on Pet { ...humanOrAlienFragment }
fragment humanOrAlienFragment on HumanOrAlien { __typename }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "humanOrAlienFragment" cannot be spread here as objects of `+
`type "Pet" can never be of type "HumanOrAlien".`, 2, 53),
})
}
func TestValidate_PossibleFragmentSpreads_UnionIntoNonOverlappingUnion(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidUnionWithinUnion on CatOrDog { ...humanOrAlienFragment }
fragment humanOrAlienFragment on HumanOrAlien { __typename }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "humanOrAlienFragment" cannot be spread here as objects of `+
`type "CatOrDog" can never be of type "HumanOrAlien".`, 2, 54),
})
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoNonImplementingObject(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidInterfaceWithinObject on Cat { ...intelligentFragment }
fragment intelligentFragment on Intelligent { iq }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "intelligentFragment" cannot be spread here as objects of `+
`type "Cat" can never be of type "Intelligent".`, 2, 54),
})
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoNonOverlappingInterface(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidInterfaceWithinInterface on Pet {
...intelligentFragment
}
fragment intelligentFragment on Intelligent { iq }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "intelligentFragment" cannot be spread here as objects of `+
`type "Pet" can never be of type "Intelligent".`, 3, 9),
})
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoNonOverlappingInterfaceInInlineFragment(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidInterfaceWithinInterfaceAnon on Pet {
...on Intelligent { iq }
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment cannot be spread here as objects of `+
`type "Pet" can never be of type "Intelligent".`, 3, 9),
})
}
func TestValidate_PossibleFragmentSpreads_InterfaceIntoNonOverlappingUnion(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidInterfaceWithinUnion on HumanOrAlien { ...petFragment }
fragment petFragment on Pet { name }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Fragment "petFragment" cannot be spread here as objects of `+
`type "HumanOrAlien" can never be of type "Pet".`, 2, 62),
})
}