diff --git a/src/directives.ts b/src/directives.ts index 28394ad652b..f3ffc70f797 100644 --- a/src/directives.ts +++ b/src/directives.ts @@ -338,9 +338,9 @@ export class SchemaDirectiveVisitor { public static getLocations() { if (this.locations === null) { this.locations = []; - for (let key in this) { + for (let key in this.prototype) { if (hasOwn.call(methodToLocationMap, key)) { - const method = this[key]; + const method = this.prototype[key]; if (typeof method === 'function' && ! visitMethodStubSet.has(method)) { this.locations.push(methodToLocationMap[key]); diff --git a/src/test/testDirectives.ts b/src/test/testDirectives.ts index 844d1d4c4ea..f4bbca1b272 100644 --- a/src/test/testDirectives.ts +++ b/src/test/testDirectives.ts @@ -260,6 +260,32 @@ describe('@directives', () => { }); }); + it('can use visitor methods to generate locations implicitly', () => { + assert.deepEqual((class extends SchemaDirectiveVisitor { + /* tslint:disable:no-empty */ + public visitSchema() {} + public visitScalar() {} + public visitObject() {} + public visitFieldDefinition() {} + public visitArgumentDefinition() {} + public visitEnum() {} + public visitEnumValue() {} + public visitInputObject() {} + public visitInputFieldDefinition() {} + /* tslint:enable:no-empty */ + }).getLocations().sort(), [ + DirectiveLocation.ARGUMENT_DEFINITION, + DirectiveLocation.ENUM, + DirectiveLocation.ENUM_VALUE, + DirectiveLocation.FIELD_DEFINITION, + DirectiveLocation.INPUT_FIELD_DEFINITION, + DirectiveLocation.INPUT_OBJECT, + DirectiveLocation.OBJECT, + DirectiveLocation.SCALAR, + DirectiveLocation.SCHEMA, + ]); + }); + it('can handle all kinds of undeclared arguments', () => { const schemaText = ` enum SpineEnum {