Skip to content

Commit

Permalink
add build schema test
Browse files Browse the repository at this point in the history
  • Loading branch information
robrichard committed Jan 9, 2020
1 parent 428edc5 commit 91e9366
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/utilities/__tests__/buildASTSchema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
GraphQLSkipDirective,
GraphQLIncludeDirective,
GraphQLDeprecatedDirective,
GraphQLStreamDirective,
GraphQLDeferDirective,
} from '../../type/directives';
import {
GraphQLID,
Expand Down Expand Up @@ -220,20 +222,30 @@ describe('Schema Builder', () => {
});

it('Overriding directives excludes specified', () => {
const schema = buildSchema(`
const schema = buildSchema(
`
directive @skip on FIELD
directive @include on FIELD
directive @deprecated on FIELD_DEFINITION
`);
directive @defer on FRAGMENT_SPREAD
directive @stream on FIELD
`,
{
experimentalStream: true,
experimentalDefer: true,
},
);

expect(schema.getDirectives()).to.have.lengthOf(3);
expect(schema.getDirectives()).to.have.lengthOf(5);
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
expect(schema.getDirective('include')).to.not.equal(
GraphQLIncludeDirective,
);
expect(schema.getDirective('deprecated')).to.not.equal(
GraphQLDeprecatedDirective,
);
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
expect(schema.getDirective('stream')).to.not.equal(GraphQLStreamDirective);
});

it('Adding directives maintains @skip & @include', () => {
Expand All @@ -247,6 +259,22 @@ describe('Schema Builder', () => {
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
});

it('Adds @stream and @defer when experimental flags are passed to schema', () => {
const schema = buildSchema('type Query', {
experimentalStream: true,
experimentalDefer: true,
});

expect(schema.getDirectives()).to.have.lengthOf(5);
expect(schema.getDirective('stream')).to.equal(GraphQLStreamDirective);
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
expect(schema.getDirective('deprecated')).to.equal(
GraphQLDeprecatedDirective,
);
});

it('Type modifiers', () => {
const sdl = dedent`
type Query {
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/buildASTSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,7 @@ export function buildSchema(
commentDescriptions: (options && options.commentDescriptions) || false,
assumeValidSDL: (options && options.assumeValidSDL) || false,
assumeValid: (options && options.assumeValid) || false,
experimentalDefer: (options && options.experimentalDefer) || false,
experimentalStream: (options && options.experimentalStream) || false,
});
}

0 comments on commit 91e9366

Please sign in to comment.