Skip to content

Commit 91e9366

Browse files
committed
add build schema test
1 parent 428edc5 commit 91e9366

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
GraphQLSkipDirective,
1717
GraphQLIncludeDirective,
1818
GraphQLDeprecatedDirective,
19+
GraphQLStreamDirective,
20+
GraphQLDeferDirective,
1921
} from '../../type/directives';
2022
import {
2123
GraphQLID,
@@ -220,20 +222,30 @@ describe('Schema Builder', () => {
220222
});
221223

222224
it('Overriding directives excludes specified', () => {
223-
const schema = buildSchema(`
225+
const schema = buildSchema(
226+
`
224227
directive @skip on FIELD
225228
directive @include on FIELD
226229
directive @deprecated on FIELD_DEFINITION
227-
`);
230+
directive @defer on FRAGMENT_SPREAD
231+
directive @stream on FIELD
232+
`,
233+
{
234+
experimentalStream: true,
235+
experimentalDefer: true,
236+
},
237+
);
228238

229-
expect(schema.getDirectives()).to.have.lengthOf(3);
239+
expect(schema.getDirectives()).to.have.lengthOf(5);
230240
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
231241
expect(schema.getDirective('include')).to.not.equal(
232242
GraphQLIncludeDirective,
233243
);
234244
expect(schema.getDirective('deprecated')).to.not.equal(
235245
GraphQLDeprecatedDirective,
236246
);
247+
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
248+
expect(schema.getDirective('stream')).to.not.equal(GraphQLStreamDirective);
237249
});
238250

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

262+
it('Adds @stream and @defer when experimental flags are passed to schema', () => {
263+
const schema = buildSchema('type Query', {
264+
experimentalStream: true,
265+
experimentalDefer: true,
266+
});
267+
268+
expect(schema.getDirectives()).to.have.lengthOf(5);
269+
expect(schema.getDirective('stream')).to.equal(GraphQLStreamDirective);
270+
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
271+
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
272+
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
273+
expect(schema.getDirective('deprecated')).to.equal(
274+
GraphQLDeprecatedDirective,
275+
);
276+
});
277+
250278
it('Type modifiers', () => {
251279
const sdl = dedent`
252280
type Query {

src/utilities/buildASTSchema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,7 @@ export function buildSchema(
154154
commentDescriptions: (options && options.commentDescriptions) || false,
155155
assumeValidSDL: (options && options.assumeValidSDL) || false,
156156
assumeValid: (options && options.assumeValid) || false,
157+
experimentalDefer: (options && options.experimentalDefer) || false,
158+
experimentalStream: (options && options.experimentalStream) || false,
157159
});
158160
}

0 commit comments

Comments
 (0)