Skip to content

Commit b592a2d

Browse files
robrichardlilianammmatos
authored andcommitted
update tests to account for new directive
1 parent 609aff6 commit b592a2d

File tree

8 files changed

+90
-17
lines changed

8 files changed

+90
-17
lines changed

src/__tests__/starWarsIntrospection-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('Star Wars Introspection Tests', () => {
4747
{ name: '__EnumValue' },
4848
{ name: '__Directive' },
4949
{ name: '__DirectiveLocation' },
50+
{ name: 'Int' },
5051
],
5152
},
5253
});

src/type/__tests__/introspection-test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,15 @@ describe('Introspection', () => {
805805
],
806806
possibleTypes: null,
807807
},
808+
{
809+
kind: 'SCALAR',
810+
name: 'Int',
811+
fields: null,
812+
inputFields: null,
813+
interfaces: null,
814+
enumValues: null,
815+
possibleTypes: null,
816+
},
808817
],
809818
directives: [
810819
{
@@ -873,6 +882,47 @@ describe('Introspection', () => {
873882
},
874883
],
875884
},
885+
{
886+
name: 'stream',
887+
locations: ['FIELD'],
888+
args: [
889+
{
890+
defaultValue: null,
891+
name: 'if',
892+
type: {
893+
kind: 'SCALAR',
894+
name: 'Boolean',
895+
ofType: null,
896+
},
897+
},
898+
{
899+
defaultValue: null,
900+
name: 'label',
901+
type: {
902+
kind: 'NON_NULL',
903+
name: null,
904+
ofType: {
905+
kind: 'SCALAR',
906+
name: 'String',
907+
ofType: null,
908+
},
909+
},
910+
},
911+
{
912+
defaultValue: null,
913+
name: 'initial_count',
914+
type: {
915+
kind: 'NON_NULL',
916+
name: null,
917+
ofType: {
918+
kind: 'SCALAR',
919+
name: 'Int',
920+
ofType: null,
921+
},
922+
},
923+
},
924+
],
925+
},
876926
{
877927
name: 'deprecated',
878928
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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
GraphQLSkipDirective,
1717
GraphQLIncludeDirective,
1818
GraphQLDeferDirective,
19+
GraphQLStreamDirective,
1920
GraphQLDeprecatedDirective,
2021
} from '../../type/directives';
2122
import {
@@ -143,7 +144,6 @@ describe('Schema Builder', () => {
143144
const schema = buildSchema('type Query');
144145

145146
// String and Boolean are always included through introspection types
146-
expect(schema.getType('Int')).to.equal(undefined);
147147
expect(schema.getType('Float')).to.equal(undefined);
148148
expect(schema.getType('ID')).to.equal(undefined);
149149
});
@@ -209,13 +209,14 @@ describe('Schema Builder', () => {
209209
expect(cycleSDL(sdl, { commentDescriptions: true })).to.equal(sdl);
210210
});
211211

212-
it('Maintains @skip, @include & @defer', () => {
212+
it('Maintains @skip, @include, @defer & stream', () => {
213213
const schema = buildSchema('type Query');
214214

215-
expect(schema.getDirectives()).to.have.lengthOf(4);
215+
expect(schema.getDirectives()).to.have.lengthOf(5);
216216
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
217217
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
218218
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
219+
expect(schema.getDirective('stream')).to.equal(GraphQLStreamDirective);
219220
expect(schema.getDirective('deprecated')).to.equal(
220221
GraphQLDeprecatedDirective,
221222
);
@@ -226,29 +227,32 @@ describe('Schema Builder', () => {
226227
directive @skip on FIELD
227228
directive @include on FIELD
228229
directive @defer on FIELD
230+
directive @stream on FRAGMENT_SPREAD
229231
directive @deprecated on FIELD_DEFINITION
230232
`);
231233

232-
expect(schema.getDirectives()).to.have.lengthOf(4);
234+
expect(schema.getDirectives()).to.have.lengthOf(5);
233235
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
234236
expect(schema.getDirective('include')).to.not.equal(
235237
GraphQLIncludeDirective,
236238
);
237239
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
240+
expect(schema.getDirective('stream')).to.not.equal(GraphQLStreamDirective);
238241
expect(schema.getDirective('deprecated')).to.not.equal(
239242
GraphQLDeprecatedDirective,
240243
);
241244
});
242245

243-
it('Adding directives maintains @skip, @include & @defer', () => {
246+
it('Adding directives maintains @skip, @include, @defer & @stream', () => {
244247
const schema = buildSchema(`
245248
directive @foo(arg: Int) on FIELD
246249
`);
247250

248-
expect(schema.getDirectives()).to.have.lengthOf(5);
251+
expect(schema.getDirectives()).to.have.lengthOf(6);
249252
expect(schema.getDirective('skip')).to.not.equal(undefined);
250253
expect(schema.getDirective('include')).to.not.equal(undefined);
251254
expect(schema.getDirective('defer')).to.not.equal(undefined);
255+
expect(schema.getDirective('stream')).to.not.equal(undefined);
252256
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
253257
});
254258

src/utilities/__tests__/buildClientSchema-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ describe('Type System: build schema from introspection', () => {
152152
const introspection = introspectionFromSchema(schema);
153153
const clientSchema = buildClientSchema(introspection);
154154

155-
expect(clientSchema.getType('Int')).to.equal(undefined);
156155
expect(clientSchema.getType('Float')).to.equal(undefined);
157156
expect(clientSchema.getType('ID')).to.equal(undefined);
158157
});

src/utilities/__tests__/extendSchema-test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { validateSchema } from '../../type/validate';
1717
import { assertDirective } from '../../type/directives';
1818
import {
1919
GraphQLID,
20-
GraphQLInt,
2120
GraphQLFloat,
2221
GraphQLString,
2322
GraphQLBoolean,
@@ -174,8 +173,7 @@ describe('extendSchema', () => {
174173
it('extends objects with standard type fields', () => {
175174
const schema = buildSchema('type Query');
176175

177-
// String and Boolean are always included through introspection types
178-
expect(schema.getType('Int')).to.equal(undefined);
176+
// String, Boolean and Int are always included through introspection types
179177
expect(schema.getType('Float')).to.equal(undefined);
180178
expect(schema.getType('String')).to.equal(GraphQLString);
181179
expect(schema.getType('Boolean')).to.equal(GraphQLBoolean);
@@ -189,7 +187,6 @@ describe('extendSchema', () => {
189187
const extendedSchema = extendSchema(schema, extendAST);
190188

191189
expect(validateSchema(extendedSchema)).to.deep.equal([]);
192-
expect(extendedSchema.getType('Int')).to.equal(undefined);
193190
expect(extendedSchema.getType('Float')).to.equal(undefined);
194191
expect(extendedSchema.getType('String')).to.equal(GraphQLString);
195192
expect(extendedSchema.getType('Boolean')).to.equal(GraphQLBoolean);
@@ -205,7 +202,6 @@ describe('extendSchema', () => {
205202
const extendedTwiceSchema = extendSchema(schema, extendTwiceAST);
206203

207204
expect(validateSchema(extendedTwiceSchema)).to.deep.equal([]);
208-
expect(extendedTwiceSchema.getType('Int')).to.equal(GraphQLInt);
209205
expect(extendedTwiceSchema.getType('Float')).to.equal(GraphQLFloat);
210206
expect(extendedTwiceSchema.getType('String')).to.equal(GraphQLString);
211207
expect(extendedTwiceSchema.getType('Boolean')).to.equal(GraphQLBoolean);

src/utilities/__tests__/schemaPrinter-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,20 @@ describe('Type System Printer', () => {
601601
label: String!
602602
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
603603
604+
"""
605+
Directs the executor to stream plural fields when the \`if\` argument is true or undefined.
606+
"""
607+
directive @stream(
608+
"""Stream when true or undefined."""
609+
if: Boolean
610+
611+
"""Unique name"""
612+
label: String!
613+
614+
"""Number of items to return immediately"""
615+
initial_count: Int!
616+
) on FIELD
617+
604618
"""Marks an element of a GraphQL schema as no longer supported."""
605619
directive @deprecated(
606620
"""
@@ -823,6 +837,18 @@ describe('Type System Printer', () => {
823837
label: String!
824838
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
825839
840+
# Directs the executor to stream plural fields when the \`if\` argument is true or undefined.
841+
directive @stream(
842+
# Stream when true or undefined.
843+
if: Boolean
844+
845+
# Unique name
846+
label: String!
847+
848+
# Number of items to return immediately
849+
initial_count: Int!
850+
) on FIELD
851+
826852
# Marks an element of a GraphQL schema as no longer supported.
827853
directive @deprecated(
828854
# 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__/KnownTypeNames-test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ describe('Validate: Known type names', () => {
8989
message: 'Unknown type "Float".',
9090
locations: [{ line: 2, column: 31 }],
9191
},
92-
{
93-
message: 'Unknown type "Int".',
94-
locations: [{ line: 2, column: 44 }],
95-
},
9692
]);
9793
});
9894

0 commit comments

Comments
 (0)