Skip to content

Commit dbece26

Browse files
lilianammmatosrobrichard
authored andcommitted
implicitly add defer directive to schema
1 parent e5ce12e commit dbece26

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
assertDirective,
1616
GraphQLSkipDirective,
1717
GraphQLIncludeDirective,
18+
GraphQLDeferDirective,
1819
GraphQLDeprecatedDirective,
1920
} from '../../type/directives';
2021
import {
@@ -208,12 +209,13 @@ describe('Schema Builder', () => {
208209
expect(cycleSDL(sdl, { commentDescriptions: true })).to.equal(sdl);
209210
});
210211

211-
it('Maintains @skip & @include', () => {
212+
it('Maintains @skip, @include & @defer', () => {
212213
const schema = buildSchema('type Query');
213214

214-
expect(schema.getDirectives()).to.have.lengthOf(3);
215+
expect(schema.getDirectives()).to.have.lengthOf(4);
215216
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
216217
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
218+
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
217219
expect(schema.getDirective('deprecated')).to.equal(
218220
GraphQLDeprecatedDirective,
219221
);
@@ -223,27 +225,30 @@ describe('Schema Builder', () => {
223225
const schema = buildSchema(`
224226
directive @skip on FIELD
225227
directive @include on FIELD
228+
directive @defer on FIELD
226229
directive @deprecated on FIELD_DEFINITION
227230
`);
228231

229-
expect(schema.getDirectives()).to.have.lengthOf(3);
232+
expect(schema.getDirectives()).to.have.lengthOf(4);
230233
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
231234
expect(schema.getDirective('include')).to.not.equal(
232235
GraphQLIncludeDirective,
233236
);
237+
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
234238
expect(schema.getDirective('deprecated')).to.not.equal(
235239
GraphQLDeprecatedDirective,
236240
);
237241
});
238242

239-
it('Adding directives maintains @skip & @include', () => {
243+
it('Adding directives maintains @skip, @include & @defer', () => {
240244
const schema = buildSchema(`
241245
directive @foo(arg: Int) on FIELD
242246
`);
243247

244-
expect(schema.getDirectives()).to.have.lengthOf(4);
248+
expect(schema.getDirectives()).to.have.lengthOf(5);
245249
expect(schema.getDirective('skip')).to.not.equal(undefined);
246250
expect(schema.getDirective('include')).to.not.equal(undefined);
251+
expect(schema.getDirective('defer')).to.not.equal(undefined);
247252
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
248253
});
249254

src/utilities/buildASTSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import {
1717
GraphQLSkipDirective,
1818
GraphQLIncludeDirective,
19+
GraphQLDeferDirective,
1920
GraphQLDeprecatedDirective,
2021
} from '../type/directives';
2122

@@ -105,6 +106,10 @@ export function buildASTSchema(
105106
directives.push(GraphQLIncludeDirective);
106107
}
107108

109+
if (!directives.some(directive => directive.name === 'defer')) {
110+
directives.push(GraphQLDeferDirective);
111+
}
112+
108113
if (!directives.some(directive => directive.name === 'deprecated')) {
109114
directives.push(GraphQLDeprecatedDirective);
110115
}

0 commit comments

Comments
 (0)