diff --git a/src/validation/__tests__/KnownDirectivesRule-test.ts b/src/validation/__tests__/KnownDirectivesRule-test.ts index e36761fbef..38173f1cd3 100644 --- a/src/validation/__tests__/KnownDirectivesRule-test.ts +++ b/src/validation/__tests__/KnownDirectivesRule-test.ts @@ -325,7 +325,9 @@ describe('Validate: Known directives', () => { myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition } - extend type MyObj @onObject + extend type MyObj @onObject { + myExtensionField(myArg: Int @onArgumentDefinition): String @onFieldDefinition + } scalar MyScalar @onScalar @@ -335,7 +337,9 @@ describe('Validate: Known directives', () => { myField(myArg: Int @onArgumentDefinition): String @onFieldDefinition } - extend interface MyInterface @onInterface + extend interface MyInterface @onInterface { + myExtensionField(myArg: Int @onArgumentDefinition): String @onFieldDefinition + } union MyUnion @onUnion = MyObj | Other @@ -351,7 +355,9 @@ describe('Validate: Known directives', () => { myField: Int @onInputFieldDefinition } - extend input MyInput @onInputObject + extend input MyInput @onInputObject { + myExtensionField: Int @onInputFieldDefinition + } schema @onSchema { query: MyQuery @@ -375,12 +381,20 @@ describe('Validate: Known directives', () => { myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition } + extend type MyObj @onDirective { + myExtensionField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition + } + scalar MyScalar @onEnum interface MyInterface @onObject { myField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition } + extend interface MyInterface @onObject { + myExtensionField(myArg: Int @onInputFieldDefinition): String @onInputFieldDefinition + } + union MyUnion @onEnumValue = MyObj | Other enum MyEnum @onScalar { @@ -391,13 +405,15 @@ describe('Validate: Known directives', () => { myField: Int @onArgumentDefinition } + extend input MyInput { + myExtensionField: Int @onArgumentDefinition + } + schema @onObject { query: MyQuery } extend schema @onObject - - extend type MyObj @onDirective `, schemaWithSDLDirectives, ).toDeepEqual([ @@ -415,56 +431,85 @@ describe('Validate: Known directives', () => { 'Directive "@onInputFieldDefinition" may not be used on FIELD_DEFINITION.', locations: [{ line: 3, column: 65 }], }, + { + message: 'Directive "@onDirective" may not be used on OBJECT.', + locations: [{ line: 6, column: 29 }], + }, + { + message: + 'Directive "@onInputFieldDefinition" may not be used on ARGUMENT_DEFINITION.', + locations: [{ line: 7, column: 41 }], + }, + { + message: + 'Directive "@onInputFieldDefinition" may not be used on FIELD_DEFINITION.', + locations: [{ line: 7, column: 74 }], + }, { message: 'Directive "@onEnum" may not be used on SCALAR.', - locations: [{ line: 6, column: 27 }], + locations: [{ line: 10, column: 27 }], }, { message: 'Directive "@onObject" may not be used on INTERFACE.', - locations: [{ line: 8, column: 33 }], + locations: [{ line: 12, column: 33 }], }, { message: 'Directive "@onInputFieldDefinition" may not be used on ARGUMENT_DEFINITION.', - locations: [{ line: 9, column: 32 }], + locations: [{ line: 13, column: 32 }], }, { message: 'Directive "@onInputFieldDefinition" may not be used on FIELD_DEFINITION.', - locations: [{ line: 9, column: 65 }], + locations: [{ line: 13, column: 65 }], + }, + { + message: 'Directive "@onObject" may not be used on INTERFACE.', + locations: [{ line: 16, column: 40 }], + }, + { + message: + 'Directive "@onInputFieldDefinition" may not be used on ARGUMENT_DEFINITION.', + locations: [{ line: 17, column: 41 }], + }, + { + message: + 'Directive "@onInputFieldDefinition" may not be used on FIELD_DEFINITION.', + locations: [{ line: 17, column: 74 }], }, { message: 'Directive "@onEnumValue" may not be used on UNION.', - locations: [{ line: 12, column: 25 }], + locations: [{ line: 20, column: 25 }], }, { message: 'Directive "@onScalar" may not be used on ENUM.', - locations: [{ line: 14, column: 23 }], + locations: [{ line: 22, column: 23 }], }, { message: 'Directive "@onUnion" may not be used on ENUM_VALUE.', - locations: [{ line: 15, column: 22 }], + locations: [{ line: 23, column: 22 }], }, { message: 'Directive "@onEnum" may not be used on INPUT_OBJECT.', - locations: [{ line: 18, column: 25 }], + locations: [{ line: 26, column: 25 }], }, { message: 'Directive "@onArgumentDefinition" may not be used on INPUT_FIELD_DEFINITION.', - locations: [{ line: 19, column: 26 }], + locations: [{ line: 27, column: 26 }], }, { - message: 'Directive "@onObject" may not be used on SCHEMA.', - locations: [{ line: 22, column: 18 }], + message: + 'Directive "@onArgumentDefinition" may not be used on INPUT_FIELD_DEFINITION.', + locations: [{ line: 31, column: 35 }], }, { message: 'Directive "@onObject" may not be used on SCHEMA.', - locations: [{ line: 26, column: 25 }], + locations: [{ line: 34, column: 18 }], }, { - message: 'Directive "@onDirective" may not be used on OBJECT.', - locations: [{ line: 28, column: 29 }], + message: 'Directive "@onObject" may not be used on SCHEMA.', + locations: [{ line: 38, column: 25 }], }, ]); }); diff --git a/src/validation/rules/KnownDirectivesRule.ts b/src/validation/rules/KnownDirectivesRule.ts index 320ecf64a1..84e77b8c8e 100644 --- a/src/validation/rules/KnownDirectivesRule.ts +++ b/src/validation/rules/KnownDirectivesRule.ts @@ -153,7 +153,8 @@ function getDirectiveLocationForASTPath( case Kind.INPUT_VALUE_DEFINITION: { const parentNode = ancestors.at(-3); invariant(parentNode != null && 'kind' in parentNode); - return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION + return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION || + parentNode.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION ? DirectiveLocation.INPUT_FIELD_DEFINITION : DirectiveLocation.ARGUMENT_DEFINITION; }