Skip to content

Commit 8fa38ee

Browse files
committed
update tests to account for new directive
1 parent 414fb9c commit 8fa38ee

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
@@ -807,6 +807,15 @@ describe('Introspection', () => {
807807
],
808808
possibleTypes: null,
809809
},
810+
{
811+
kind: 'SCALAR',
812+
name: 'Int',
813+
fields: null,
814+
inputFields: null,
815+
interfaces: null,
816+
enumValues: null,
817+
possibleTypes: null,
818+
},
810819
],
811820
directives: [
812821
{
@@ -875,6 +884,47 @@ describe('Introspection', () => {
875884
},
876885
],
877886
},
887+
{
888+
name: 'stream',
889+
locations: ['FIELD'],
890+
args: [
891+
{
892+
defaultValue: null,
893+
name: 'if',
894+
type: {
895+
kind: 'SCALAR',
896+
name: 'Boolean',
897+
ofType: null,
898+
},
899+
},
900+
{
901+
defaultValue: null,
902+
name: 'label',
903+
type: {
904+
kind: 'NON_NULL',
905+
name: null,
906+
ofType: {
907+
kind: 'SCALAR',
908+
name: 'String',
909+
ofType: null,
910+
},
911+
},
912+
},
913+
{
914+
defaultValue: null,
915+
name: 'initial_count',
916+
type: {
917+
kind: 'NON_NULL',
918+
name: null,
919+
ofType: {
920+
kind: 'SCALAR',
921+
name: 'Int',
922+
ofType: null,
923+
},
924+
},
925+
},
926+
],
927+
},
878928
{
879929
name: 'deprecated',
880930
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 {
@@ -117,7 +118,6 @@ describe('Schema Builder', () => {
117118
const schema = buildSchema('type Query');
118119

119120
// String and Boolean are always included through introspection types
120-
expect(schema.getType('Int')).to.equal(undefined);
121121
expect(schema.getType('Float')).to.equal(undefined);
122122
expect(schema.getType('ID')).to.equal(undefined);
123123
});
@@ -183,13 +183,14 @@ describe('Schema Builder', () => {
183183
expect(cycleSDL(sdl, { commentDescriptions: true })).to.equal(sdl);
184184
});
185185

186-
it('Maintains @skip, @include & @defer', () => {
186+
it('Maintains @skip, @include, @defer & stream', () => {
187187
const schema = buildSchema('type Query');
188188

189-
expect(schema.getDirectives()).to.have.lengthOf(4);
189+
expect(schema.getDirectives()).to.have.lengthOf(5);
190190
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
191191
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
192192
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
193+
expect(schema.getDirective('stream')).to.equal(GraphQLStreamDirective);
193194
expect(schema.getDirective('deprecated')).to.equal(
194195
GraphQLDeprecatedDirective,
195196
);
@@ -200,29 +201,32 @@ describe('Schema Builder', () => {
200201
directive @skip on FIELD
201202
directive @include on FIELD
202203
directive @defer on FIELD
204+
directive @stream on FRAGMENT_SPREAD
203205
directive @deprecated on FIELD_DEFINITION
204206
`);
205207

206-
expect(schema.getDirectives()).to.have.lengthOf(4);
208+
expect(schema.getDirectives()).to.have.lengthOf(5);
207209
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
208210
expect(schema.getDirective('include')).to.not.equal(
209211
GraphQLIncludeDirective,
210212
);
211213
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
214+
expect(schema.getDirective('stream')).to.not.equal(GraphQLStreamDirective);
212215
expect(schema.getDirective('deprecated')).to.not.equal(
213216
GraphQLDeprecatedDirective,
214217
);
215218
});
216219

217-
it('Adding directives maintains @skip, @include & @defer', () => {
220+
it('Adding directives maintains @skip, @include, @defer & @stream', () => {
218221
const schema = buildSchema(`
219222
directive @foo(arg: Int) on FIELD
220223
`);
221224

222-
expect(schema.getDirectives()).to.have.lengthOf(5);
225+
expect(schema.getDirectives()).to.have.lengthOf(6);
223226
expect(schema.getDirective('skip')).to.not.equal(undefined);
224227
expect(schema.getDirective('include')).to.not.equal(undefined);
225228
expect(schema.getDirective('defer')).to.not.equal(undefined);
229+
expect(schema.getDirective('stream')).to.not.equal(undefined);
226230
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
227231
});
228232

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,
@@ -213,8 +212,7 @@ describe('extendSchema', () => {
213212
it('extends objects with standard type fields', () => {
214213
const schema = buildSchema('type Query');
215214

216-
// String and Boolean are always included through introspection types
217-
expect(schema.getType('Int')).to.equal(undefined);
215+
// String, Boolean and Int are always included through introspection types
218216
expect(schema.getType('Float')).to.equal(undefined);
219217
expect(schema.getType('String')).to.equal(GraphQLString);
220218
expect(schema.getType('Boolean')).to.equal(GraphQLBoolean);
@@ -227,7 +225,6 @@ describe('extendSchema', () => {
227225
`);
228226
const extendedSchema = extendSchema(schema, extendAST);
229227

230-
expect(extendedSchema.getType('Int')).to.equal(undefined);
231228
expect(extendedSchema.getType('Float')).to.equal(undefined);
232229
expect(extendedSchema.getType('String')).to.equal(GraphQLString);
233230
expect(extendedSchema.getType('Boolean')).to.equal(GraphQLBoolean);
@@ -242,7 +239,6 @@ describe('extendSchema', () => {
242239
`);
243240
const extendedTwiceSchema = extendSchema(schema, extendTwiceAST);
244241

245-
expect(extendedTwiceSchema.getType('Int')).to.equal(GraphQLInt);
246242
expect(extendedTwiceSchema.getType('Float')).to.equal(GraphQLFloat);
247243
expect(extendedTwiceSchema.getType('String')).to.equal(GraphQLString);
248244
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)