Skip to content

Commit 0c6129e

Browse files
committed
Add @stream directive to specified directives
1 parent e2c0ebd commit 0c6129e

15 files changed

+109
-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.d.ts

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

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: 44 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,40 @@ 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: '0',
999+
name: 'initialCount',
1000+
type: {
1001+
kind: 'SCALAR',
1002+
name: 'Int',
1003+
ofType: null,
1004+
},
1005+
},
1006+
],
1007+
},
9641008
{
9651009
name: 'deprecated',
9661010
isRepeatable: false,

src/type/__tests__/schema-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ describe('Type System: Schema', () => {
294294
'ASub',
295295
'Boolean',
296296
'String',
297+
'Int',
297298
'__Schema',
298299
'__Type',
299300
'__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: 27 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
/**
@@ -193,6 +193,31 @@ export const GraphQLDeferDirective = new GraphQLDirective({
193193
},
194194
});
195195

196+
/**
197+
* Used to conditionally stream list fields.
198+
*/
199+
export const GraphQLStreamDirective = new GraphQLDirective({
200+
name: 'stream',
201+
description:
202+
'Directs the executor to stream plural fields when the `if` argument is true or undefined.',
203+
locations: [DirectiveLocation.FIELD],
204+
args: {
205+
if: {
206+
type: GraphQLBoolean,
207+
description: 'Stream when true or undefined.',
208+
},
209+
label: {
210+
type: GraphQLString,
211+
description: 'Unique name',
212+
},
213+
initialCount: {
214+
defaultValue: 0,
215+
type: GraphQLInt,
216+
description: 'Number of items to return immediately',
217+
},
218+
},
219+
});
220+
196221
/**
197222
* Constant string used for default reason for a deprecation.
198223
*/
@@ -242,6 +267,7 @@ export const specifiedDirectives = Object.freeze([
242267
GraphQLIncludeDirective,
243268
GraphQLSkipDirective,
244269
GraphQLDeferDirective,
270+
GraphQLStreamDirective,
245271
GraphQLDeprecatedDirective,
246272
GraphQLSpecifiedByDirective,
247273
]);

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,
@@ -158,8 +159,7 @@ describe('Schema Builder', () => {
158159
it('include standard type only if it is used', () => {
159160
const schema = buildSchema('type Query');
160161

161-
// String and Boolean are always included through introspection types
162-
expect(schema.getType('Int')).to.equal(undefined);
162+
// String, Boolean, and Int are always included through introspection types
163163
expect(schema.getType('Float')).to.equal(undefined);
164164
expect(schema.getType('ID')).to.equal(undefined);
165165
});
@@ -225,10 +225,11 @@ describe('Schema Builder', () => {
225225
it('Maintains specified directives', () => {
226226
const schema = buildSchema('type Query');
227227

228-
expect(schema.getDirectives()).to.have.lengthOf(5);
228+
expect(schema.getDirectives()).to.have.lengthOf(6);
229229
expect(schema.getDirective('skip')).to.equal(GraphQLSkipDirective);
230230
expect(schema.getDirective('include')).to.equal(GraphQLIncludeDirective);
231231
expect(schema.getDirective('defer')).to.equal(GraphQLDeferDirective);
232+
expect(schema.getDirective('stream')).to.equal(GraphQLStreamDirective);
232233
expect(schema.getDirective('deprecated')).to.equal(
233234
GraphQLDeprecatedDirective,
234235
);
@@ -244,9 +245,10 @@ describe('Schema Builder', () => {
244245
directive @deprecated on FIELD_DEFINITION
245246
directive @specifiedBy on FIELD_DEFINITION
246247
directive @defer on FRAGMENT_SPREAD
248+
directive @stream on FIELD
247249
`);
248250

249-
expect(schema.getDirectives()).to.have.lengthOf(5);
251+
expect(schema.getDirectives()).to.have.lengthOf(6);
250252
expect(schema.getDirective('skip')).to.not.equal(GraphQLSkipDirective);
251253
expect(schema.getDirective('include')).to.not.equal(
252254
GraphQLIncludeDirective,
@@ -258,17 +260,19 @@ describe('Schema Builder', () => {
258260
GraphQLSpecifiedByDirective,
259261
);
260262
expect(schema.getDirective('defer')).to.not.equal(GraphQLDeferDirective);
263+
expect(schema.getDirective('stream')).to.not.equal(GraphQLStreamDirective);
261264
});
262265

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

268-
expect(schema.getDirectives()).to.have.lengthOf(6);
271+
expect(schema.getDirectives()).to.have.lengthOf(7);
269272
expect(schema.getDirective('skip')).to.not.equal(undefined);
270273
expect(schema.getDirective('include')).to.not.equal(undefined);
271274
expect(schema.getDirective('defer')).to.not.equal(undefined);
275+
expect(schema.getDirective('stream')).to.not.equal(undefined);
272276
expect(schema.getDirective('deprecated')).to.not.equal(undefined);
273277
expect(schema.getDirective('specifiedBy')).to.not.equal(undefined);
274278
});

src/utilities/__tests__/buildClientSchema-test.js

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

153-
expect(clientSchema.getType('Int')).to.equal(undefined);
154153
expect(clientSchema.getType('Float')).to.equal(undefined);
155154
expect(clientSchema.getType('ID')).to.equal(undefined);
156155
});

src/utilities/__tests__/extendSchema-test.js

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

138-
// String and Boolean are always included through introspection types
139-
expect(schema.getType('Int')).to.equal(undefined);
138+
// String, Boolean, and Int are always included through introspection types
140139
expect(schema.getType('Float')).to.equal(undefined);
141140
expect(schema.getType('String')).to.equal(GraphQLString);
142141
expect(schema.getType('Boolean')).to.equal(GraphQLBoolean);
@@ -150,7 +149,6 @@ describe('extendSchema', () => {
150149
const extendedSchema = extendSchema(schema, extendAST);
151150

152151
expect(validateSchema(extendedSchema)).to.deep.equal([]);
153-
expect(extendedSchema.getType('Int')).to.equal(undefined);
154152
expect(extendedSchema.getType('Float')).to.equal(undefined);
155153
expect(extendedSchema.getType('String')).to.equal(GraphQLString);
156154
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: 14 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 = 0
653+
) on FIELD
654+
641655
"""Marks an element of a GraphQL schema as no longer supported."""
642656
directive @deprecated(
643657
"""

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)