Skip to content

Commit 8b669b8

Browse files
committed
added tests for defer directive
1 parent 6daf03b commit 8b669b8

File tree

8 files changed

+466
-6
lines changed

8 files changed

+466
-6
lines changed

src/execution/__tests__/directives-test.js

Lines changed: 388 additions & 1 deletion
Large diffs are not rendered by default.

src/type/__tests__/introspection-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,34 @@ describe('Introspection', () => {
845845
},
846846
],
847847
},
848+
{
849+
name: 'defer',
850+
locations: ['FRAGMENT_SPREAD'],
851+
args: [
852+
{
853+
defaultValue: null,
854+
name: 'if',
855+
type: {
856+
kind: 'SCALAR',
857+
name: 'Boolean',
858+
ofType: null,
859+
},
860+
},
861+
{
862+
defaultValue: null,
863+
name: 'label',
864+
type: {
865+
kind: 'NON_NULL',
866+
name: null,
867+
ofType: {
868+
kind: 'SCALAR',
869+
name: 'String',
870+
ofType: null,
871+
},
872+
},
873+
},
874+
],
875+
},
848876
{
849877
name: 'deprecated',
850878
locations: ['FIELD_DEFINITION', 'ENUM_VALUE'],

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { validateSchema } from '../../type/validate';
1414
import {
1515
assertDirective,
1616
GraphQLSkipDirective,
17+
GraphQLDeferDirective,
1718
GraphQLIncludeDirective,
1819
GraphQLDeprecatedDirective,
1920
} from '../../type/directives';
@@ -211,9 +212,10 @@ describe('Schema Builder', () => {
211212
it('Maintains @skip & @include', () => {
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
);
@@ -224,27 +226,30 @@ describe('Schema Builder', () => {
224226
directive @skip on FIELD
225227
directive @include on FIELD
226228
directive @deprecated on FIELD_DEFINITION
229+
directive @defer on FRAGMENT_SPREAD
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
);
234237
expect(schema.getDirective('deprecated')).to.not.equal(
235238
GraphQLDeprecatedDirective,
236239
);
240+
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
237241
});
238242

239243
it('Adding directives maintains @skip & @include', () => {
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);
247251
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
252+
expect(schema.getDirective('defer')).to.not.equal(undefined);
248253
});
249254

250255
it('Type modifiers', () => {

src/utilities/__tests__/findBreakingChanges-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GraphQLSchema } from '../../type/schema';
77
import {
88
GraphQLSkipDirective,
99
GraphQLIncludeDirective,
10+
GraphQLDeferDirective,
1011
GraphQLDeprecatedDirective,
1112
} from '../../type/directives';
1213

@@ -790,7 +791,11 @@ describe('findBreakingChanges', () => {
790791
const oldSchema = new GraphQLSchema({});
791792

792793
const newSchema = new GraphQLSchema({
793-
directives: [GraphQLSkipDirective, GraphQLIncludeDirective],
794+
directives: [
795+
GraphQLSkipDirective,
796+
GraphQLIncludeDirective,
797+
GraphQLDeferDirective,
798+
],
794799
});
795800

796801
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,15 @@ describe('Type System Printer', () => {
590590
if: Boolean!
591591
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
592592
593+
"""Directs the executor to defer fragment when the \`if\` argument is true."""
594+
directive @defer(
595+
"""Deferred when true."""
596+
if: Boolean
597+
598+
"""label"""
599+
label: String!
600+
) on FRAGMENT_SPREAD
601+
593602
"""Marks an element of a GraphQL schema as no longer supported."""
594603
directive @deprecated(
595604
"""
@@ -803,6 +812,15 @@ describe('Type System Printer', () => {
803812
if: Boolean!
804813
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
805814
815+
# Directs the executor to defer fragment when the \`if\` argument is true.
816+
directive @defer(
817+
# Deferred when true.
818+
if: Boolean
819+
820+
# label
821+
label: String!
822+
) on FRAGMENT_SPREAD
823+
806824
# Marks an element of a GraphQL schema as no longer supported.
807825
directive @deprecated(
808826
# Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).

src/validation/__tests__/KnownDirectives-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe('Validate: Known directives', () => {
6161
human @skip(if: false) {
6262
name
6363
}
64+
...DeferFrag @defer(if: true)
6465
}
6566
`);
6667
});
@@ -116,6 +117,8 @@ describe('Validate: Known directives', () => {
116117
...Frag @include(if: true)
117118
skippedField @skip(if: true)
118119
...SkippedFrag @skip(if: true)
120+
...DeferVarFrag @defer(if: $var)
121+
...DeferFrag @defer(if: true)
119122
}
120123
121124
mutation Bar @onMutation {
@@ -135,7 +138,7 @@ describe('Validate: Known directives', () => {
135138
it('with misplaced directives', () => {
136139
expectErrors(`
137140
query Foo($var: Boolean) @include(if: true) {
138-
name @onQuery @include(if: $var)
141+
name @onQuery @include(if: $var) @defer(if: $var)
139142
...Frag @onQuery
140143
}
141144
@@ -151,6 +154,10 @@ describe('Validate: Known directives', () => {
151154
message: 'Directive "@onQuery" may not be used on FIELD.',
152155
locations: [{ line: 3, column: 14 }],
153156
},
157+
{
158+
message: 'Directive "@defer" may not be used on FIELD.',
159+
locations: [{ line: 3, column: 42 }],
160+
},
154161
{
155162
message: 'Directive "@onQuery" may not be used on FRAGMENT_SPREAD.',
156163
locations: [{ line: 4, column: 17 }],

src/validation/__tests__/ProvidedRequiredArguments-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ describe('Validate: Provided required arguments', () => {
227227
human @skip(if: false) {
228228
name
229229
}
230+
...DeferFrag @defer(label: "DeferFrag_defer")
231+
...DeferIfFrag @defer(if: true, label: "DeferFrag_defer")
230232
}
231233
`);
232234
});
@@ -237,6 +239,7 @@ describe('Validate: Provided required arguments', () => {
237239
dog @include {
238240
name @skip
239241
}
242+
...DeferFrag @defer
240243
}
241244
`).to.deep.equal([
242245
{
@@ -249,6 +252,11 @@ describe('Validate: Provided required arguments', () => {
249252
'Directive "@skip" argument "if" of type "Boolean!" is required, but it was not provided.',
250253
locations: [{ line: 4, column: 18 }],
251254
},
255+
{
256+
message:
257+
'Directive "@defer" argument "label" of type "String!" is required, but it was not provided.',
258+
locations: [{ line: 6, column: 24 }],
259+
},
252260
]);
253261
});
254262
});

src/validation/__tests__/harness.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
GraphQLDirective,
1212
GraphQLIncludeDirective,
1313
GraphQLSkipDirective,
14+
GraphQLDeferDirective,
1415
} from '../../type/directives';
1516
import {
1617
GraphQLInt,
@@ -362,6 +363,7 @@ export const testSchema = new GraphQLSchema({
362363
directives: [
363364
GraphQLIncludeDirective,
364365
GraphQLSkipDirective,
366+
GraphQLDeferDirective,
365367
new GraphQLDirective({
366368
name: 'onQuery',
367369
locations: ['QUERY'],

0 commit comments

Comments
 (0)