diff --git a/src/language/__tests__/schema-parser-test.js b/src/language/__tests__/schema-parser-test.js index 1c9fe0f144c..c35e99a4f3b 100644 --- a/src/language/__tests__/schema-parser-test.js +++ b/src/language/__tests__/schema-parser-test.js @@ -263,6 +263,66 @@ extend type Hello { ); }); + it('Schema extension', () => { + const body = ` + extend schema { + mutation: Mutation + }`; + const doc = parse(body); + const expected = { + kind: 'Document', + definitions: [ + { + kind: 'SchemaExtension', + directives: [], + operationTypes: [ + { + kind: 'OperationTypeDefinition', + operation: 'mutation', + type: typeNode('Mutation', { start: 41, end: 49 }), + loc: { start: 31, end: 49 }, + }, + ], + loc: { start: 7, end: 57 }, + }, + ], + loc: { start: 0, end: 57 }, + }; + expect(printJson(doc)).to.equal(printJson(expected)); + }); + + it('Schema extension with only directives', () => { + const body = 'extend schema @directive'; + const doc = parse(body); + const expected = { + kind: 'Document', + definitions: [ + { + kind: 'SchemaExtension', + directives: [ + { + kind: 'Directive', + name: nameNode('directive', { start: 15, end: 24 }), + arguments: [], + loc: { start: 14, end: 24 }, + }, + ], + operationTypes: [], + loc: { start: 0, end: 24 }, + }, + ], + loc: { start: 0, end: 24 }, + }; + expect(printJson(doc)).to.equal(printJson(expected)); + }); + + it('Schema extension without anything throws', () => { + expectSyntaxError('extend schema', 'Unexpected ', { + line: 1, + column: 14, + }); + }); + it('Simple non-null type', () => { const body = ` type Hello { diff --git a/src/validation/__tests__/ExecutableDefinitions-test.js b/src/validation/__tests__/ExecutableDefinitions-test.js index 3a626a31430..922420bb32e 100644 --- a/src/validation/__tests__/ExecutableDefinitions-test.js +++ b/src/validation/__tests__/ExecutableDefinitions-test.js @@ -87,10 +87,13 @@ describe('Validate: Executable definitions', () => { type Query { test: String } + + extend schema @directive `, [ nonExecutableDefinition('schema', 2, 7), nonExecutableDefinition('Query', 6, 7), + nonExecutableDefinition('schema', 10, 7), ], ); }); diff --git a/src/validation/__tests__/KnownDirectives-test.js b/src/validation/__tests__/KnownDirectives-test.js index ae460296509..0e0daf5641f 100644 --- a/src/validation/__tests__/KnownDirectives-test.js +++ b/src/validation/__tests__/KnownDirectives-test.js @@ -178,6 +178,8 @@ describe('Validate: Known directives', () => { schema @onSchema { query: MyQuery } + + extend schema @onSchema `, ); }); @@ -209,6 +211,8 @@ describe('Validate: Known directives', () => { schema @onObject { query: MyQuery } + + extend schema @onObject `, [ misplacedDirective('onInterface', 'OBJECT', 2, 43), @@ -249,6 +253,7 @@ describe('Validate: Known directives', () => { 24, ), misplacedDirective('onObject', 'SCHEMA', 22, 16), + misplacedDirective('onObject', 'SCHEMA', 26, 23), ], ); });