Skip to content

Commit

Permalink
Add parsing and validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Apr 19, 2018
1 parent 6e65e8e commit f47bb47
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/language/__tests__/schema-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EOF>', {
line: 1,
column: 14,
});
});

it('Simple non-null type', () => {
const body = `
type Hello {
Expand Down
3 changes: 3 additions & 0 deletions src/validation/__tests__/ExecutableDefinitions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
);
});
Expand Down
5 changes: 5 additions & 0 deletions src/validation/__tests__/KnownDirectives-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ describe('Validate: Known directives', () => {
schema @onSchema {
query: MyQuery
}
extend schema @onSchema
`,
);
});
Expand Down Expand Up @@ -209,6 +211,8 @@ describe('Validate: Known directives', () => {
schema @onObject {
query: MyQuery
}
extend schema @onObject
`,
[
misplacedDirective('onInterface', 'OBJECT', 2, 43),
Expand Down Expand Up @@ -249,6 +253,7 @@ describe('Validate: Known directives', () => {
24,
),
misplacedDirective('onObject', 'SCHEMA', 22, 16),
misplacedDirective('onObject', 'SCHEMA', 26, 23),
],
);
});
Expand Down

0 comments on commit f47bb47

Please sign in to comment.