@@ -74,14 +74,16 @@ describe('Validate: Known directives', () => {
74
74
` ) ;
75
75
} ) ;
76
76
77
- it ( 'with known directives' , ( ) => {
77
+ it ( 'with standard directives' , ( ) => {
78
78
expectValid ( `
79
79
{
80
- dog @include(if: true) {
81
- name
82
- }
83
80
human @skip(if: false) {
84
81
name
82
+ pets {
83
+ ... on Dog @include(if: true) {
84
+ name
85
+ }
86
+ }
85
87
}
86
88
}
87
89
` ) ;
@@ -90,121 +92,140 @@ describe('Validate: Known directives', () => {
90
92
it ( 'with unknown directive' , ( ) => {
91
93
expectErrors ( `
92
94
{
93
- dog @unknown(directive: "value") {
95
+ human @unknown(directive: "value") {
94
96
name
95
97
}
96
98
}
97
99
` ) . to . deep . equal ( [
98
100
{
99
101
message : 'Unknown directive "@unknown".' ,
100
- locations : [ { line : 3 , column : 13 } ] ,
102
+ locations : [ { line : 3 , column : 15 } ] ,
101
103
} ,
102
104
] ) ;
103
105
} ) ;
104
106
105
107
it ( 'with many unknown directives' , ( ) => {
106
108
expectErrors ( `
107
109
{
108
- dog @unknown(directive: "value") {
109
- name
110
- }
111
- human @unknown(directive: "value") {
110
+ __typename @unknown
111
+ human @unknown {
112
112
name
113
- pets @unknown(directive: "value") {
113
+ pets @unknown {
114
114
name
115
115
}
116
116
}
117
117
}
118
118
` ) . to . deep . equal ( [
119
119
{
120
120
message : 'Unknown directive "@unknown".' ,
121
- locations : [ { line : 3 , column : 13 } ] ,
121
+ locations : [ { line : 3 , column : 20 } ] ,
122
122
} ,
123
123
{
124
124
message : 'Unknown directive "@unknown".' ,
125
- locations : [ { line : 6 , column : 15 } ] ,
125
+ locations : [ { line : 4 , column : 15 } ] ,
126
126
} ,
127
127
{
128
128
message : 'Unknown directive "@unknown".' ,
129
- locations : [ { line : 8 , column : 16 } ] ,
129
+ locations : [ { line : 6 , column : 16 } ] ,
130
130
} ,
131
131
] ) ;
132
132
} ) ;
133
133
134
134
it ( 'with well placed directives' , ( ) => {
135
135
expectValid ( `
136
- query ($var: Boolean) @onQuery {
137
- name @include(if: $var)
138
- ...Frag @include(if: true)
139
- skippedField @skip(if: true)
140
- ...SkippedFrag @skip(if: true)
141
-
142
- ... @skip(if: true) {
143
- skippedField
136
+ query ($var: Boolean @onVariableDefinition) @onQuery {
137
+ human @onField {
138
+ ...Frag @onFragmentSpread
139
+ ... @onInlineFragment {
140
+ name @onField
141
+ }
144
142
}
145
143
}
146
144
147
145
mutation @onMutation {
148
- someField
146
+ someField @onField
149
147
}
150
148
151
149
subscription @onSubscription {
152
- someField
150
+ someField @onField
153
151
}
154
152
155
- fragment Frag on SomeType @onFragmentDefinition {
156
- someField
157
- }
158
- ` ) ;
159
- } ) ;
160
-
161
- it ( 'with well placed variable definition directive' , ( ) => {
162
- expectValid ( `
163
- query Foo($var: Boolean @onVariableDefinition) {
164
- name
153
+ fragment Frag on Human @onFragmentDefinition {
154
+ name @onField
165
155
}
166
156
` ) ;
167
157
} ) ;
168
158
169
159
it ( 'with misplaced directives' , ( ) => {
170
160
expectErrors ( `
171
- query Foo($var: Boolean) @include(if: true) {
172
- name @onQuery @include(if: $var)
173
- ...Frag @onQuery
161
+ query ($var: Boolean @onQuery) @onMutation {
162
+ human @onQuery {
163
+ ...Frag @onQuery
164
+ ... @onQuery {
165
+ name @onQuery
166
+ }
167
+ }
168
+ }
169
+
170
+ mutation @onQuery {
171
+ someField @onQuery
174
172
}
175
173
176
- mutation Bar @onQuery {
177
- someField
174
+ subscription @onQuery {
175
+ someField @onQuery
176
+ }
177
+
178
+ fragment Frag on Human @onQuery {
179
+ name @onQuery
178
180
}
179
181
` ) . to . deep . equal ( [
180
182
{
181
- message : 'Directive "@include" may not be used on QUERY.' ,
182
- locations : [ { line : 2 , column : 32 } ] ,
183
+ message : 'Directive "@onQuery" may not be used on VARIABLE_DEFINITION.' ,
184
+ locations : [ { line : 2 , column : 28 } ] ,
185
+ } ,
186
+ {
187
+ message : 'Directive "@onMutation" may not be used on QUERY.' ,
188
+ locations : [ { line : 2 , column : 38 } ] ,
183
189
} ,
184
190
{
185
191
message : 'Directive "@onQuery" may not be used on FIELD.' ,
186
- locations : [ { line : 3 , column : 14 } ] ,
192
+ locations : [ { line : 3 , column : 15 } ] ,
187
193
} ,
188
194
{
189
195
message : 'Directive "@onQuery" may not be used on FRAGMENT_SPREAD.' ,
190
- locations : [ { line : 4 , column : 17 } ] ,
196
+ locations : [ { line : 4 , column : 19 } ] ,
197
+ } ,
198
+ {
199
+ message : 'Directive "@onQuery" may not be used on INLINE_FRAGMENT.' ,
200
+ locations : [ { line : 5 , column : 15 } ] ,
201
+ } ,
202
+ {
203
+ message : 'Directive "@onQuery" may not be used on FIELD.' ,
204
+ locations : [ { line : 6 , column : 18 } ] ,
191
205
} ,
192
206
{
193
207
message : 'Directive "@onQuery" may not be used on MUTATION.' ,
194
- locations : [ { line : 7 , column : 20 } ] ,
208
+ locations : [ { line : 11 , column : 16 } ] ,
195
209
} ,
196
- ] ) ;
197
- } ) ;
198
-
199
- it ( 'with misplaced variable definition directive' , ( ) => {
200
- expectErrors ( `
201
- query Foo($var: Boolean @onField) {
202
- name
203
- }
204
- ` ) . to . deep . equal ( [
205
210
{
206
- message : 'Directive "@onField" may not be used on VARIABLE_DEFINITION.' ,
207
- locations : [ { line : 2 , column : 31 } ] ,
211
+ message : 'Directive "@onQuery" may not be used on FIELD.' ,
212
+ locations : [ { column : 19 , line : 12 } ] ,
213
+ } ,
214
+ {
215
+ message : 'Directive "@onQuery" may not be used on SUBSCRIPTION.' ,
216
+ locations : [ { column : 20 , line : 15 } ] ,
217
+ } ,
218
+ {
219
+ message : 'Directive "@onQuery" may not be used on FIELD.' ,
220
+ locations : [ { column : 19 , line : 16 } ] ,
221
+ } ,
222
+ {
223
+ message : 'Directive "@onQuery" may not be used on FRAGMENT_DEFINITION.' ,
224
+ locations : [ { column : 30 , line : 19 } ] ,
225
+ } ,
226
+ {
227
+ message : 'Directive "@onQuery" may not be used on FIELD.' ,
228
+ locations : [ { column : 14 , line : 20 } ] ,
208
229
} ,
209
230
] ) ;
210
231
} ) ;
0 commit comments