Skip to content

Commit b9444ae

Browse files
committed
update tests to account for new directive
1 parent a3b278f commit b9444ae

File tree

6 files changed

+23
-67
lines changed

6 files changed

+23
-67
lines changed

src/__tests__/starWarsDeferredQuery-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ describe('Star Wars Query Deferred Tests', () => {
2525
`;
2626
const result = await graphql(StarWarsSchema, query);
2727
expect(result).to.deep.equal({
28-
data: {
29-
hero: {
30-
id: '2001',
31-
name: 'R2-D2',
28+
errors: [
29+
{
30+
message: 'Unknown directive "@defer".',
31+
locations: [{ line: 5, column: 29 }],
3232
},
33-
},
33+
],
3434
});
3535
});
3636
});
@@ -125,7 +125,7 @@ describe('Star Wars Query Deferred Tests', () => {
125125
label: 'DeferNested',
126126
path: ['hero'],
127127
data: {
128-
appearsIn: ['NEWHOPE', 'EMPIRE', 'JEDI'],
128+
appearsIn: ['NEW_HOPE', 'EMPIRE', 'JEDI'],
129129
primaryFunction: 'Astromech',
130130
},
131131
});

src/type/__tests__/introspection-test.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -845,34 +845,6 @@ describe('Introspection', () => {
845845
},
846846
],
847847
},
848-
{
849-
name: 'defer',
850-
locations: ['FRAGMENT_SPREAD', 'INLINE_FRAGMENT'],
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-
},
876848
{
877849
name: 'deprecated',
878850
locations: ['FIELD_DEFINITION', 'ENUM_VALUE'],

src/type/directives.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
type DirectiveLocationEnum,
2121
} from '../language/directiveLocation';
2222

23-
import { GraphQLString, GraphQLBoolean } from './scalars';
23+
import { GraphQLString, GraphQLBoolean, GraphQLInt } from './scalars';
2424
import {
2525
type GraphQLFieldConfigArgumentMap,
2626
type GraphQLArgument,
@@ -209,6 +209,7 @@ export const GraphQLStreamDirective = new GraphQLDirective({
209209
type: GraphQLNonNull(GraphQLString),
210210
description: 'Unique name',
211211
},
212+
// eslint-disable-next-line camelcase
212213
initial_count: {
213214
type: GraphQLNonNull(GraphQLInt),
214215
description: 'Number of items to return immediately',

src/utilities/__tests__/buildASTSchema-test.js

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

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

215-
expect(schema.getDirectives()).to.have.lengthOf(4);
214+
expect(schema.getDirectives()).to.have.lengthOf(3);
216215
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
217216
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
218-
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
219217
expect(schema.getDirective('deprecated')).to.equal(
220218
GraphQLDeprecatedDirective,
221219
);
@@ -225,30 +223,27 @@ describe('Schema Builder', () => {
225223
const schema = buildSchema(`
226224
directive @skip on FIELD
227225
directive @include on FIELD
228-
directive @defer on FIELD
229226
directive @deprecated on FIELD_DEFINITION
230227
`);
231228

232-
expect(schema.getDirectives()).to.have.lengthOf(4);
229+
expect(schema.getDirectives()).to.have.lengthOf(3);
233230
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
234231
expect(schema.getDirective('include')).to.not.equal(
235232
GraphQLIncludeDirective,
236233
);
237-
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
238234
expect(schema.getDirective('deprecated')).to.not.equal(
239235
GraphQLDeprecatedDirective,
240236
);
241237
});
242238

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

248-
expect(schema.getDirectives()).to.have.lengthOf(5);
244+
expect(schema.getDirectives()).to.have.lengthOf(4);
249245
expect(schema.getDirective('skip')).to.not.equal(undefined);
250246
expect(schema.getDirective('include')).to.not.equal(undefined);
251-
expect(schema.getDirective('defer')).to.not.equal(undefined);
252247
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
253248
});
254249

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -590,17 +590,6 @@ describe('Type System Printer', () => {
590590
if: Boolean!
591591
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
592592
593-
"""
594-
Directs the executor to defer this fragment when the \`if\` argument is true or undefined.
595-
"""
596-
directive @defer(
597-
"""Deferred when true or undefined."""
598-
if: Boolean
599-
600-
"""Unique name"""
601-
label: String!
602-
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
603-
604593
"""Marks an element of a GraphQL schema as no longer supported."""
605594
directive @deprecated(
606595
"""
@@ -814,15 +803,6 @@ describe('Type System Printer', () => {
814803
if: Boolean!
815804
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
816805
817-
# Directs the executor to defer this fragment when the \`if\` argument is true or undefined.
818-
directive @defer(
819-
# Deferred when true or undefined.
820-
if: Boolean
821-
822-
# Unique name
823-
label: String!
824-
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
825-
826806
# Marks an element of a GraphQL schema as no longer supported.
827807
directive @deprecated(
828808
# 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/utilities/buildASTSchema.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,19 @@ export function buildASTSchema(
107107
directives.push(GraphQLIncludeDirective);
108108
}
109109

110-
if (!directives.some(directive => directive.name === 'defer')) {
110+
if (
111+
options &&
112+
options.experimentalDeferFragmentSpreads &&
113+
!directives.some(directive => directive.name === 'defer')
114+
) {
111115
directives.push(GraphQLDeferDirective);
112116
}
113117

114-
if (!directives.some(directive => directive.name === 'stream')) {
118+
if (
119+
options &&
120+
options.experimentalStream &&
121+
!directives.some(directive => directive.name === 'stream')
122+
) {
115123
directives.push(GraphQLStreamDirective);
116124
}
117125

0 commit comments

Comments
 (0)