@@ -191,46 +191,92 @@ describe('Validate: Known directives', () => {
191
191
` ) . to . deep . equal ( [ ] ) ;
192
192
} ) ;
193
193
194
- it ( 'with well placed directives' , ( ) => {
194
+ it ( 'with directive defined in schema extension' , ( ) => {
195
+ const schema = buildSchema ( `
196
+ type Query {
197
+ foo: String
198
+ }
199
+ ` ) ;
195
200
expectSDLErrors (
196
201
`
197
- type MyObj implements MyInterface @onObject {
198
- myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
199
- }
202
+ directive @test on OBJECT
200
203
201
- extend type MyObj @onObject
204
+ extend type Query @test
205
+ ` ,
206
+ schema ,
207
+ ) . to . deep . equal ( [ ] ) ;
208
+ } ) ;
202
209
203
- scalar MyScalar @onScalar
210
+ it ( 'with directive used in schema extension' , ( ) => {
211
+ const schema = buildSchema ( `
212
+ directive @test on OBJECT
204
213
205
- extend scalar MyScalar @onScalar
214
+ type Query {
215
+ foo: String
216
+ }
217
+ ` ) ;
218
+ expectSDLErrors (
219
+ `
220
+ extend type Query @test
221
+ ` ,
222
+ schema ,
223
+ ) . to . deep . equal ( [ ] ) ;
224
+ } ) ;
206
225
207
- interface MyInterface @onInterface {
208
- myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
226
+ it ( 'with unknown directive in schema extension' , ( ) => {
227
+ const schema = buildSchema ( `
228
+ type Query {
229
+ foo: String
209
230
}
231
+ ` ) ;
232
+ expectSDLErrors (
233
+ `
234
+ extend type Query @unknown
235
+ ` ,
236
+ schema ,
237
+ ) . to . deep . equal ( [ unknownDirective ( 'unknown' , 2 , 29 ) ] ) ;
238
+ } ) ;
210
239
211
- extend interface MyInterface @onInterface
240
+ it ( 'with well placed directives' , ( ) => {
241
+ expectSDLErrors (
242
+ `
243
+ type MyObj implements MyInterface @onObject {
244
+ myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
245
+ }
212
246
213
- union MyUnion @onUnion = MyObj | Other
247
+ extend type MyObj @onObject
214
248
215
- extend union MyUnion @onUnion
249
+ scalar MyScalar @onScalar
216
250
217
- enum MyEnum @onEnum {
218
- MY_VALUE @onEnumValue
219
- }
251
+ extend scalar MyScalar @onScalar
220
252
221
- extend enum MyEnum @onEnum
253
+ interface MyInterface @onInterface {
254
+ myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition
255
+ }
222
256
223
- input MyInput @onInputObject {
224
- myField: Int @onInputFieldDefinition
225
- }
257
+ extend interface MyInterface @onInterface
226
258
227
- extend input MyInput @onInputObject
259
+ union MyUnion @onUnion = MyObj | Other
228
260
229
- schema @onSchema {
230
- query: MyQuery
231
- }
261
+ extend union MyUnion @onUnion
262
+
263
+ enum MyEnum @onEnum {
264
+ MY_VALUE @onEnumValue
265
+ }
266
+
267
+ extend enum MyEnum @onEnum
268
+
269
+ input MyInput @onInputObject {
270
+ myField: Int @onInputFieldDefinition
271
+ }
272
+
273
+ extend input MyInput @onInputObject
274
+
275
+ schema @onSchema {
276
+ query: MyQuery
277
+ }
232
278
233
- extend schema @onSchema
279
+ extend schema @onSchema
234
280
` ,
235
281
schemaWithSDLDirectives ,
236
282
) . to . deep . equal ( [ ] ) ;
@@ -239,63 +285,63 @@ describe('Validate: Known directives', () => {
239
285
it ( 'with misplaced directives' , ( ) => {
240
286
expectSDLErrors (
241
287
`
242
- type MyObj implements MyInterface @onInterface {
243
- myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
244
- }
288
+ type MyObj implements MyInterface @onInterface {
289
+ myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
290
+ }
245
291
246
- scalar MyScalar @onEnum
292
+ scalar MyScalar @onEnum
247
293
248
- interface MyInterface @onObject {
249
- myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
250
- }
294
+ interface MyInterface @onObject {
295
+ myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition
296
+ }
251
297
252
- union MyUnion @onEnumValue = MyObj | Other
298
+ union MyUnion @onEnumValue = MyObj | Other
253
299
254
- enum MyEnum @onScalar {
255
- MY_VALUE @onUnion
256
- }
300
+ enum MyEnum @onScalar {
301
+ MY_VALUE @onUnion
302
+ }
257
303
258
- input MyInput @onEnum {
259
- myField: Int @onArgumentDefinition
260
- }
304
+ input MyInput @onEnum {
305
+ myField: Int @onArgumentDefinition
306
+ }
261
307
262
- schema @onObject {
263
- query: MyQuery
264
- }
308
+ schema @onObject {
309
+ query: MyQuery
310
+ }
265
311
266
- extend schema @onObject
312
+ extend schema @onObject
267
313
` ,
268
314
schemaWithSDLDirectives ,
269
315
) . to . deep . equal ( [
270
- misplacedDirective ( 'onInterface' , 'OBJECT' , 2 , 43 ) ,
316
+ misplacedDirective ( 'onInterface' , 'OBJECT' , 2 , 45 ) ,
271
317
misplacedDirective (
272
318
'onInputFieldDefinition' ,
273
319
'ARGUMENT_DEFINITION' ,
274
320
3 ,
275
- 30 ,
321
+ 32 ,
276
322
) ,
277
- misplacedDirective ( 'onInputFieldDefinition' , 'FIELD_DEFINITION' , 3 , 63 ) ,
278
- misplacedDirective ( 'onEnum' , 'SCALAR' , 6 , 25 ) ,
279
- misplacedDirective ( 'onObject' , 'INTERFACE' , 8 , 31 ) ,
323
+ misplacedDirective ( 'onInputFieldDefinition' , 'FIELD_DEFINITION' , 3 , 65 ) ,
324
+ misplacedDirective ( 'onEnum' , 'SCALAR' , 6 , 27 ) ,
325
+ misplacedDirective ( 'onObject' , 'INTERFACE' , 8 , 33 ) ,
280
326
misplacedDirective (
281
327
'onInputFieldDefinition' ,
282
328
'ARGUMENT_DEFINITION' ,
283
329
9 ,
284
- 30 ,
330
+ 32 ,
285
331
) ,
286
- misplacedDirective ( 'onInputFieldDefinition' , 'FIELD_DEFINITION' , 9 , 63 ) ,
287
- misplacedDirective ( 'onEnumValue' , 'UNION' , 12 , 23 ) ,
288
- misplacedDirective ( 'onScalar' , 'ENUM' , 14 , 21 ) ,
289
- misplacedDirective ( 'onUnion' , 'ENUM_VALUE' , 15 , 20 ) ,
290
- misplacedDirective ( 'onEnum' , 'INPUT_OBJECT' , 18 , 23 ) ,
332
+ misplacedDirective ( 'onInputFieldDefinition' , 'FIELD_DEFINITION' , 9 , 65 ) ,
333
+ misplacedDirective ( 'onEnumValue' , 'UNION' , 12 , 25 ) ,
334
+ misplacedDirective ( 'onScalar' , 'ENUM' , 14 , 23 ) ,
335
+ misplacedDirective ( 'onUnion' , 'ENUM_VALUE' , 15 , 22 ) ,
336
+ misplacedDirective ( 'onEnum' , 'INPUT_OBJECT' , 18 , 25 ) ,
291
337
misplacedDirective (
292
338
'onArgumentDefinition' ,
293
339
'INPUT_FIELD_DEFINITION' ,
294
340
19 ,
295
- 24 ,
341
+ 26 ,
296
342
) ,
297
- misplacedDirective ( 'onObject' , 'SCHEMA' , 22 , 16 ) ,
298
- misplacedDirective ( 'onObject' , 'SCHEMA' , 26 , 23 ) ,
343
+ misplacedDirective ( 'onObject' , 'SCHEMA' , 22 , 18 ) ,
344
+ misplacedDirective ( 'onObject' , 'SCHEMA' , 26 , 25 ) ,
299
345
] ) ;
300
346
} ) ;
301
347
} ) ;
0 commit comments