Skip to content

Commit 0100e57

Browse files
committed
Add @stream directive to specified directives
# Conflicts: # src/index.d.ts # src/type/directives.d.ts # src/type/directives.ts # src/type/index.js
1 parent c93bf4d commit 0100e57

File tree

12 files changed

+102
-15
lines changed

12 files changed

+102
-15
lines changed

src/__tests__/starWarsIntrospection-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('Star Wars Introspection Tests', () => {
3737
{ name: 'Droid' },
3838
{ name: 'Query' },
3939
{ name: 'Boolean' },
40+
{ name: 'Int' },
4041
{ name: '__Schema' },
4142
{ name: '__Type' },
4243
{ name: '__TypeKind' },

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export {
5656
GraphQLIncludeDirective,
5757
GraphQLSkipDirective,
5858
GraphQLDeferDirective,
59+
GraphQLStreamDirective,
5960
GraphQLDeprecatedDirective,
6061
GraphQLSpecifiedByDirective,
6162
/** "Enum" of Type Kinds */

src/type/__tests__/introspection-test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ describe('Introspection', () => {
7878
enumValues: null,
7979
possibleTypes: null,
8080
},
81+
{
82+
kind: 'SCALAR',
83+
name: 'Int',
84+
specifiedByURL: null,
85+
fields: null,
86+
inputFields: null,
87+
interfaces: null,
88+
enumValues: null,
89+
possibleTypes: null,
90+
},
8191
{
8292
kind: 'OBJECT',
8393
name: '__Schema',
@@ -973,6 +983,40 @@ describe('Introspection', () => {
973983
},
974984
],
975985
},
986+
{
987+
name: 'stream',
988+
isRepeatable: false,
989+
locations: ['FIELD'],
990+
args: [
991+
{
992+
defaultValue: null,
993+
name: 'if',
994+
type: {
995+
kind: 'SCALAR',
996+
name: 'Boolean',
997+
ofType: null,
998+
},
999+
},
1000+
{
1001+
defaultValue: null,
1002+
name: 'label',
1003+
type: {
1004+
kind: 'SCALAR',
1005+
name: 'String',
1006+
ofType: null,
1007+
},
1008+
},
1009+
{
1010+
defaultValue: '0',
1011+
name: 'initialCount',
1012+
type: {
1013+
kind: 'SCALAR',
1014+
name: 'Int',
1015+
ofType: null,
1016+
},
1017+
},
1018+
],
1019+
},
9761020
{
9771021
name: 'deprecated',
9781022
isRepeatable: false,

src/type/__tests__/schema-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ describe('Type System: Schema', () => {
296296
'ASub',
297297
'Boolean',
298298
'String',
299+
'Int',
299300
'__Schema',
300301
'__Type',
301302
'__TypeKind',

src/type/directives.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
GraphQLFieldConfigArgumentMap,
1414
} from './definition';
1515
import { assertName } from './assertName';
16-
import { GraphQLString, GraphQLBoolean } from './scalars';
16+
import { GraphQLString, GraphQLBoolean, GraphQLInt } from './scalars';
1717
import {
1818
defineArguments,
1919
argsToArgsConfig,
@@ -188,6 +188,31 @@ export const GraphQLDeferDirective = new GraphQLDirective({
188188
},
189189
});
190190

191+
/**
192+
* Used to conditionally stream list fields.
193+
*/
194+
export const GraphQLStreamDirective = new GraphQLDirective({
195+
name: 'stream',
196+
description:
197+
'Directs the executor to stream plural fields when the `if` argument is true or undefined.',
198+
locations: [DirectiveLocation.FIELD],
199+
args: {
200+
if: {
201+
type: GraphQLBoolean,
202+
description: 'Stream when true or undefined.',
203+
},
204+
label: {
205+
type: GraphQLString,
206+
description: 'Unique name',
207+
},
208+
initialCount: {
209+
defaultValue: 0,
210+
type: GraphQLInt,
211+
description: 'Number of items to return immediately',
212+
},
213+
},
214+
});
215+
191216
/**
192217
* Constant string used for default reason for a deprecation.
193218
*/
@@ -240,6 +265,7 @@ export const specifiedDirectives: ReadonlyArray<GraphQLDirective> =
240265
GraphQLIncludeDirective,
241266
GraphQLSkipDirective,
242267
GraphQLDeferDirective,
268+
GraphQLStreamDirective,
243269
GraphQLDeprecatedDirective,
244270
GraphQLSpecifiedByDirective,
245271
]);

src/type/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export {
130130
GraphQLIncludeDirective,
131131
GraphQLSkipDirective,
132132
GraphQLDeferDirective,
133+
GraphQLStreamDirective,
133134
GraphQLDeprecatedDirective,
134135
GraphQLSpecifiedByDirective,
135136
/** Constant Deprecation Reason */

src/utilities/__tests__/buildASTSchema-test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
GraphQLDeprecatedDirective,
2121
GraphQLSpecifiedByDirective,
2222
GraphQLDeferDirective,
23+
GraphQLStreamDirective,
2324
} from '../../type/directives';
2425
import {
2526
GraphQLID,
@@ -156,8 +157,7 @@ describe('Schema Builder', () => {
156157
it('include standard type only if it is used', () => {
157158
const schema = buildSchema('type Query');
158159

159-
// String and Boolean are always included through introspection types
160-
expect(schema.getType('Int')).to.equal(undefined);
160+
// String, Boolean, and Int are always included through introspection types
161161
expect(schema.getType('Float')).to.equal(undefined);
162162
expect(schema.getType('ID')).to.equal(undefined);
163163
});
@@ -223,10 +223,11 @@ describe('Schema Builder', () => {
223223
it('Maintains specified directives', () => {
224224
const schema = buildSchema('type Query');
225225

226-
expect(schema.getDirectives()).to.have.lengthOf(5);
226+
expect(schema.getDirectives()).to.have.lengthOf(6);
227227
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
228228
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
229229
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
230+
expect(schema.getDirective('stream')).to.equal(GraphQLStreamDirective);
230231
expect(schema.getDirective('deprecated')).to.equal(
231232
GraphQLDeprecatedDirective,
232233
);
@@ -242,9 +243,10 @@ describe('Schema Builder', () => {
242243
directive @deprecated on FIELD_DEFINITION
243244
directive @specifiedBy on FIELD_DEFINITION
244245
directive @defer on FRAGMENT_SPREAD
246+
directive @stream on FIELD
245247
`);
246248

247-
expect(schema.getDirectives()).to.have.lengthOf(5);
249+
expect(schema.getDirectives()).to.have.lengthOf(6);
248250
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
249251
expect(schema.getDirective('include')).to.not.equal(
250252
GraphQLIncludeDirective,
@@ -256,17 +258,19 @@ describe('Schema Builder', () => {
256258
GraphQLSpecifiedByDirective,
257259
);
258260
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
261+
expect(schema.getDirective('stream')).to.not.equal(GraphQLStreamDirective);
259262
});
260263

261264
it('Adding directives maintains specified directives', () => {
262265
const schema = buildSchema(`
263266
directive @foo(arg: Int) on FIELD
264267
`);
265268

266-
expect(schema.getDirectives()).to.have.lengthOf(6);
269+
expect(schema.getDirectives()).to.have.lengthOf(7);
267270
expect(schema.getDirective('skip')).to.not.equal(undefined);
268271
expect(schema.getDirective('include')).to.not.equal(undefined);
269272
expect(schema.getDirective('defer')).to.not.equal(undefined);
273+
expect(schema.getDirective('stream')).to.not.equal(undefined);
270274
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
271275
expect(schema.getDirective('specifiedBy')).to.not.equal(undefined);
272276
});

src/utilities/__tests__/buildClientSchema-test.ts

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

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

src/utilities/__tests__/extendSchema-test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ describe('extendSchema', () => {
131131
it('extends objects with standard type fields', () => {
132132
const schema = buildSchema('type Query');
133133

134-
// String and Boolean are always included through introspection types
135-
expect(schema.getType('Int')).to.equal(undefined);
134+
// String, Boolean, and Int are always included through introspection types
136135
expect(schema.getType('Float')).to.equal(undefined);
137136
expect(schema.getType('String')).to.equal(GraphQLString);
138137
expect(schema.getType('Boolean')).to.equal(GraphQLBoolean);
@@ -146,7 +145,6 @@ describe('extendSchema', () => {
146145
const extendedSchema = extendSchema(schema, extendAST);
147146

148147
expect(validateSchema(extendedSchema)).to.deep.equal([]);
149-
expect(extendedSchema.getType('Int')).to.equal(undefined);
150148
expect(extendedSchema.getType('Float')).to.equal(undefined);
151149
expect(extendedSchema.getType('String')).to.equal(GraphQLString);
152150
expect(extendedSchema.getType('Boolean')).to.equal(GraphQLBoolean);

src/utilities/__tests__/findBreakingChanges-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GraphQLSchema } from '../../type/schema';
55
import {
66
GraphQLSkipDirective,
77
GraphQLDeferDirective,
8+
GraphQLStreamDirective,
89
GraphQLIncludeDirective,
910
GraphQLSpecifiedByDirective,
1011
GraphQLDeprecatedDirective,
@@ -804,6 +805,7 @@ describe('findBreakingChanges', () => {
804805
GraphQLIncludeDirective,
805806
GraphQLSpecifiedByDirective,
806807
GraphQLDeferDirective,
808+
GraphQLStreamDirective,
807809
],
808810
});
809811

src/utilities/__tests__/printSchema-test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,20 @@ describe('Type System Printer', () => {
639639
label: String
640640
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
641641
642+
"""
643+
Directs the executor to stream plural fields when the \`if\` argument is true or undefined.
644+
"""
645+
directive @stream(
646+
"""Stream when true or undefined."""
647+
if: Boolean
648+
649+
"""Unique name"""
650+
label: String
651+
652+
"""Number of items to return immediately"""
653+
initialCount: Int = 0
654+
) on FIELD
655+
642656
"""Marks an element of a GraphQL schema as no longer supported."""
643657
directive @deprecated(
644658
"""

src/validation/__tests__/KnownTypeNamesRule-test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('Validate: Known type names', () => {
8181
it('references to standard scalars that are missing in schema', () => {
8282
const schema = buildSchema('type Query { foo: String }');
8383
const query = `
84-
query ($id: ID, $float: Float, $int: Int) {
84+
query ($id: ID, $float: Float) {
8585
__typename
8686
}
8787
`;
@@ -94,10 +94,6 @@ describe('Validate: Known type names', () => {
9494
message: 'Unknown type "Float".',
9595
locations: [{ line: 2, column: 31 }],
9696
},
97-
{
98-
message: 'Unknown type "Int".',
99-
locations: [{ line: 2, column: 44 }],
100-
},
10197
]);
10298
});
10399

0 commit comments

Comments
 (0)