Skip to content

Commit f47bb47

Browse files
committed
Add parsing and validation tests
1 parent 6e65e8e commit f47bb47

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/language/__tests__/schema-parser-test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,66 @@ extend type Hello {
263263
);
264264
});
265265

266+
it('Schema extension', () => {
267+
const body = `
268+
extend schema {
269+
mutation: Mutation
270+
}`;
271+
const doc = parse(body);
272+
const expected = {
273+
kind: 'Document',
274+
definitions: [
275+
{
276+
kind: 'SchemaExtension',
277+
directives: [],
278+
operationTypes: [
279+
{
280+
kind: 'OperationTypeDefinition',
281+
operation: 'mutation',
282+
type: typeNode('Mutation', { start: 41, end: 49 }),
283+
loc: { start: 31, end: 49 },
284+
},
285+
],
286+
loc: { start: 7, end: 57 },
287+
},
288+
],
289+
loc: { start: 0, end: 57 },
290+
};
291+
expect(printJson(doc)).to.equal(printJson(expected));
292+
});
293+
294+
it('Schema extension with only directives', () => {
295+
const body = 'extend schema @directive';
296+
const doc = parse(body);
297+
const expected = {
298+
kind: 'Document',
299+
definitions: [
300+
{
301+
kind: 'SchemaExtension',
302+
directives: [
303+
{
304+
kind: 'Directive',
305+
name: nameNode('directive', { start: 15, end: 24 }),
306+
arguments: [],
307+
loc: { start: 14, end: 24 },
308+
},
309+
],
310+
operationTypes: [],
311+
loc: { start: 0, end: 24 },
312+
},
313+
],
314+
loc: { start: 0, end: 24 },
315+
};
316+
expect(printJson(doc)).to.equal(printJson(expected));
317+
});
318+
319+
it('Schema extension without anything throws', () => {
320+
expectSyntaxError('extend schema', 'Unexpected <EOF>', {
321+
line: 1,
322+
column: 14,
323+
});
324+
});
325+
266326
it('Simple non-null type', () => {
267327
const body = `
268328
type Hello {

src/validation/__tests__/ExecutableDefinitions-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ describe('Validate: Executable definitions', () => {
8787
type Query {
8888
test: String
8989
}
90+
91+
extend schema @directive
9092
`,
9193
[
9294
nonExecutableDefinition('schema', 2, 7),
9395
nonExecutableDefinition('Query', 6, 7),
96+
nonExecutableDefinition('schema', 10, 7),
9497
],
9598
);
9699
});

src/validation/__tests__/KnownDirectives-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ describe('Validate: Known directives', () => {
178178
schema @onSchema {
179179
query: MyQuery
180180
}
181+
182+
extend schema @onSchema
181183
`,
182184
);
183185
});
@@ -209,6 +211,8 @@ describe('Validate: Known directives', () => {
209211
schema @onObject {
210212
query: MyQuery
211213
}
214+
215+
extend schema @onObject
212216
`,
213217
[
214218
misplacedDirective('onInterface', 'OBJECT', 2, 43),
@@ -249,6 +253,7 @@ describe('Validate: Known directives', () => {
249253
24,
250254
),
251255
misplacedDirective('onObject', 'SCHEMA', 22, 16),
256+
misplacedDirective('onObject', 'SCHEMA', 26, 23),
252257
],
253258
);
254259
});

0 commit comments

Comments
 (0)