Skip to content

Commit 12b6c74

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 51dd5a4 commit 12b6c74

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
@@ -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.ts

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

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

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

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)