Skip to content

Commit 293a89f

Browse files
committed
Add @stream directive to specified directives
1 parent 43efcb5 commit 293a89f

14 files changed

+123
-15
lines changed

src/__tests__/starWarsIntrospection-test.js

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.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export {
5454
GraphQLIncludeDirective,
5555
GraphQLSkipDirective,
5656
GraphQLDeferDirective,
57+
GraphQLStreamDirective,
5758
GraphQLDeprecatedDirective,
5859
GraphQLSpecifiedByDirective,
5960
// "Enum" of Type Kinds

src/type/__tests__/introspection-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ describe('Introspection', () => {
7676
enumValues: null,
7777
possibleTypes: null,
7878
},
79+
{
80+
kind: 'SCALAR',
81+
name: 'Int',
82+
specifiedByUrl: null,
83+
fields: null,
84+
inputFields: null,
85+
interfaces: null,
86+
enumValues: null,
87+
possibleTypes: null,
88+
},
7989
{
8090
kind: 'OBJECT',
8191
name: '__Schema',
@@ -961,6 +971,44 @@ describe('Introspection', () => {
961971
},
962972
],
963973
},
974+
{
975+
name: 'stream',
976+
isRepeatable: false,
977+
locations: ['FIELD'],
978+
args: [
979+
{
980+
defaultValue: null,
981+
name: 'if',
982+
type: {
983+
kind: 'SCALAR',
984+
name: 'Boolean',
985+
ofType: null,
986+
},
987+
},
988+
{
989+
defaultValue: null,
990+
name: 'label',
991+
type: {
992+
kind: 'SCALAR',
993+
name: 'String',
994+
ofType: null,
995+
},
996+
},
997+
{
998+
defaultValue: null,
999+
name: 'initialCount',
1000+
type: {
1001+
kind: 'NON_NULL',
1002+
name: null,
1003+
ofType: {
1004+
kind: 'SCALAR',
1005+
name: 'Int',
1006+
ofType: null,
1007+
},
1008+
},
1009+
},
1010+
],
1011+
},
9641012
{
9651013
name: 'deprecated',
9661014
isRepeatable: false,

src/type/__tests__/schema-test.js

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

src/type/directives.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export const GraphQLSkipDirective: GraphQLDirective;
7878
*/
7979
export const GraphQLDeferDirective: GraphQLDirective;
8080

81+
/**
82+
* Used to conditionally stream list fields.
83+
*/
84+
export const GraphQLStreamDirective: GraphQLDirective;
85+
8186
/**
8287
* Used to provide a URL for specifying the behavior of custom scalar definitions.
8388
*/

src/type/directives.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
GraphQLArgument,
1818
GraphQLFieldConfigArgumentMap,
1919
} from './definition';
20-
import { GraphQLString, GraphQLBoolean } from './scalars';
20+
import { GraphQLString, GraphQLBoolean, GraphQLInt } from './scalars';
2121
import { argsToArgsConfig, GraphQLNonNull } from './definition';
2222

2323
/**
@@ -191,6 +191,30 @@ export const GraphQLDeferDirective = new GraphQLDirective({
191191
},
192192
});
193193

194+
/**
195+
* Used to conditionally stream list fields.
196+
*/
197+
export const GraphQLStreamDirective = new GraphQLDirective({
198+
name: 'stream',
199+
description:
200+
'Directs the executor to stream plural fields when the `if` argument is true or undefined.',
201+
locations: [DirectiveLocation.FIELD],
202+
args: {
203+
if: {
204+
type: GraphQLBoolean,
205+
description: 'Stream when true or undefined.',
206+
},
207+
label: {
208+
type: GraphQLString,
209+
description: 'Unique name',
210+
},
211+
initialCount: {
212+
type: new GraphQLNonNull(GraphQLInt),
213+
description: 'Number of items to return immediately',
214+
},
215+
},
216+
});
217+
194218
/**
195219
* Constant string used for default reason for a deprecation.
196220
*/
@@ -240,6 +264,7 @@ export const specifiedDirectives = Object.freeze([
240264
GraphQLIncludeDirective,
241265
GraphQLSkipDirective,
242266
GraphQLDeferDirective,
267+
GraphQLStreamDirective,
243268
GraphQLDeprecatedDirective,
244269
GraphQLSpecifiedByDirective,
245270
]);

src/type/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export {
126126
GraphQLIncludeDirective,
127127
GraphQLSkipDirective,
128128
GraphQLDeferDirective,
129+
GraphQLStreamDirective,
129130
GraphQLDeprecatedDirective,
130131
GraphQLSpecifiedByDirective,
131132
// Constant Deprecation Reason

src/type/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export {
7777
GraphQLIncludeDirective,
7878
GraphQLSkipDirective,
7979
GraphQLDeferDirective,
80+
GraphQLStreamDirective,
8081
GraphQLDeprecatedDirective,
8182
GraphQLSpecifiedByDirective,
8283
// Constant Deprecation Reason

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
GraphQLDeprecatedDirective,
2222
GraphQLSpecifiedByDirective,
2323
GraphQLDeferDirective,
24+
GraphQLStreamDirective,
2425
} from '../../type/directives';
2526
import {
2627
GraphQLID,
@@ -162,8 +163,7 @@ describe('Schema Builder', () => {
162163
it('include standard type only if it is used', () => {
163164
const schema = buildSchema('type Query');
164165

165-
// String and Boolean are always included through introspection types
166-
expect(schema.getType('Int')).to.equal(undefined);
166+
// String, Boolean, and Int are always included through introspection types
167167
expect(schema.getType('Float')).to.equal(undefined);
168168
expect(schema.getType('ID')).to.equal(undefined);
169169
});
@@ -255,10 +255,11 @@ describe('Schema Builder', () => {
255255
it('Maintains specified directives', () => {
256256
const schema = buildSchema('type Query');
257257

258-
expect(schema.getDirectives()).to.have.lengthOf(5);
258+
expect(schema.getDirectives()).to.have.lengthOf(6);
259259
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
260260
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
261261
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
262+
expect(schema.getDirective('stream')).to.equal(GraphQLStreamDirective);
262263
expect(schema.getDirective('deprecated')).to.equal(
263264
GraphQLDeprecatedDirective,
264265
);
@@ -274,9 +275,10 @@ describe('Schema Builder', () => {
274275
directive @deprecated on FIELD_DEFINITION
275276
directive @specifiedBy on FIELD_DEFINITION
276277
directive @defer on FRAGMENT_SPREAD
278+
directive @stream on FIELD
277279
`);
278280

279-
expect(schema.getDirectives()).to.have.lengthOf(5);
281+
expect(schema.getDirectives()).to.have.lengthOf(6);
280282
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
281283
expect(schema.getDirective('include')).to.not.equal(
282284
GraphQLIncludeDirective,
@@ -288,17 +290,19 @@ describe('Schema Builder', () => {
288290
GraphQLSpecifiedByDirective,
289291
);
290292
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
293+
expect(schema.getDirective('stream')).to.not.equal(GraphQLStreamDirective);
291294
});
292295

293296
it('Adding directives maintains specified directives', () => {
294297
const schema = buildSchema(`
295298
directive @foo(arg: Int) on FIELD
296299
`);
297300

298-
expect(schema.getDirectives()).to.have.lengthOf(6);
301+
expect(schema.getDirectives()).to.have.lengthOf(7);
299302
expect(schema.getDirective('skip')).to.not.equal(undefined);
300303
expect(schema.getDirective('include')).to.not.equal(undefined);
301304
expect(schema.getDirective('defer')).to.not.equal(undefined);
305+
expect(schema.getDirective('stream')).to.not.equal(undefined);
302306
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
303307
expect(schema.getDirective('specifiedBy')).to.not.equal(undefined);
304308
});

src/utilities/__tests__/buildClientSchema-test.js

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

158-
expect(clientSchema.getType('Int')).to.equal(undefined);
159158
expect(clientSchema.getType('Float')).to.equal(undefined);
160159
expect(clientSchema.getType('ID')).to.equal(undefined);
161160
});

src/utilities/__tests__/extendSchema-test.js

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

202-
// String and Boolean are always included through introspection types
203-
expect(schema.getType('Int')).to.equal(undefined);
202+
// String, Boolean, and Int are always included through introspection types
204203
expect(schema.getType('Float')).to.equal(undefined);
205204
expect(schema.getType('String')).to.equal(GraphQLString);
206205
expect(schema.getType('Boolean')).to.equal(GraphQLBoolean);
@@ -214,7 +213,6 @@ describe('extendSchema', () => {
214213
const extendedSchema = extendSchema(schema, extendAST);
215214

216215
expect(validateSchema(extendedSchema)).to.deep.equal([]);
217-
expect(extendedSchema.getType('Int')).to.equal(undefined);
218216
expect(extendedSchema.getType('Float')).to.equal(undefined);
219217
expect(extendedSchema.getType('String')).to.equal(GraphQLString);
220218
expect(extendedSchema.getType('Boolean')).to.equal(GraphQLBoolean);

src/utilities/__tests__/findBreakingChanges-test.js

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.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,20 @@ describe('Type System Printer', () => {
638638
label: String
639639
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
640640
641+
"""
642+
Directs the executor to stream plural fields when the \`if\` argument is true or undefined.
643+
"""
644+
directive @stream(
645+
"""Stream when true or undefined."""
646+
if: Boolean
647+
648+
"""Unique name"""
649+
label: String
650+
651+
"""Number of items to return immediately"""
652+
initialCount: Int!
653+
) on FIELD
654+
641655
"""Marks an element of a GraphQL schema as no longer supported."""
642656
directive @deprecated(
643657
"""
@@ -872,6 +886,18 @@ describe('Type System Printer', () => {
872886
label: String
873887
) on FRAGMENT_SPREAD | INLINE_FRAGMENT
874888
889+
# Directs the executor to stream plural fields when the \`if\` argument is true or undefined.
890+
directive @stream(
891+
# Stream when true or undefined.
892+
if: Boolean
893+
894+
# Unique name
895+
label: String
896+
897+
# Number of items to return immediately
898+
initialCount: Int!
899+
) on FIELD
900+
875901
# Marks an element of a GraphQL schema as no longer supported.
876902
directive @deprecated(
877903
# 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__/KnownTypeNamesRule-test.js

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)