Skip to content

Commit 3f7dd47

Browse files
implicitly add defer directive to schema
1 parent e2e17ca commit 3f7dd47

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 {
@@ -182,12 +183,13 @@ describe('Schema Builder', () => {
182183
expect(cycleSDL(sdl, { commentDescriptions: true })).to.equal(sdl);
183184
});
184185

185-
it('Maintains @skip & @include', () => {
186+
it('Maintains @skip, @include & @defer', () => {
186187
const schema = buildSchema('type Query');
187188

188-
expect(schema.getDirectives()).to.have.lengthOf(3);
189+
expect(schema.getDirectives()).to.have.lengthOf(4);
189190
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
190191
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
192+
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
191193
expect(schema.getDirective('deprecated')).to.equal(
192194
GraphQLDeprecatedDirective,
193195
);
@@ -197,27 +199,30 @@ describe('Schema Builder', () => {
197199
const schema = buildSchema(`
198200
directive @skip on FIELD
199201
directive @include on FIELD
202+
directive @defer on FIELD
200203
directive @deprecated on FIELD_DEFINITION
201204
`);
202205

203-
expect(schema.getDirectives()).to.have.lengthOf(3);
206+
expect(schema.getDirectives()).to.have.lengthOf(4);
204207
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
205208
expect(schema.getDirective('include')).to.not.equal(
206209
GraphQLIncludeDirective,
207210
);
211+
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
208212
expect(schema.getDirective('deprecated')).to.not.equal(
209213
GraphQLDeprecatedDirective,
210214
);
211215
});
212216

213-
it('Adding directives maintains @skip & @include', () => {
217+
it('Adding directives maintains @skip, @include & @defer', () => {
214218
const schema = buildSchema(`
215219
directive @foo(arg: Int) on FIELD
216220
`);
217221

218-
expect(schema.getDirectives()).to.have.lengthOf(4);
222+
expect(schema.getDirectives()).to.have.lengthOf(5);
219223
expect(schema.getDirective('skip')).to.not.equal(undefined);
220224
expect(schema.getDirective('include')).to.not.equal(undefined);
225+
expect(schema.getDirective('defer')).to.not.equal(undefined);
221226
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
222227
});
223228

src/utilities/buildASTSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
GraphQLDirective,
5555
GraphQLSkipDirective,
5656
GraphQLIncludeDirective,
57+
GraphQLDeferDirective,
5758
GraphQLDeprecatedDirective,
5859
} from '../type/directives';
5960
import {
@@ -170,6 +171,10 @@ export function buildASTSchema(
170171
directives.push(GraphQLIncludeDirective);
171172
}
172173

174+
if (!directives.some(directive => directive.name === 'defer')) {
175+
directives.push(GraphQLDeferDirective);
176+
}
177+
173178
if (!directives.some(directive => directive.name === 'deprecated')) {
174179
directives.push(GraphQLDeprecatedDirective);
175180
}

0 commit comments

Comments
 (0)