Skip to content

Commit 414fb9c

Browse files
committed
set up new directive
1 parent 0e05077 commit 414fb9c

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

src/type/directives.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,30 @@ export const GraphQLDeferDirective = new GraphQLDirective({
192192
},
193193
});
194194

195+
/**
196+
* Used to conditionally defer fragments.
197+
*/
198+
export const GraphQLStreamDirective = new GraphQLDirective({
199+
name: 'stream',
200+
description:
201+
'Directs the executor to stream plural fields when the `if` argument is true or undefined.',
202+
locations: [DirectiveLocation.FIELD],
203+
args: {
204+
if: {
205+
type: GraphQLBoolean,
206+
description: 'Stream when true or undefined.',
207+
},
208+
label: {
209+
type: GraphQLNonNull(GraphQLString),
210+
description: 'Unique name',
211+
},
212+
initial_count: {
213+
type: GraphQLNonNull(GraphQLInt),
214+
description: 'Number of items to return immediately',
215+
},
216+
},
217+
});
218+
195219
/**
196220
* Constant string used for default reason for a deprecation.
197221
*/
@@ -221,6 +245,7 @@ export const specifiedDirectives = Object.freeze([
221245
GraphQLIncludeDirective,
222246
GraphQLSkipDirective,
223247
GraphQLDeferDirective,
248+
GraphQLStreamDirective,
224249
GraphQLDeprecatedDirective,
225250
]);
226251

src/type/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export {
7979
GraphQLIncludeDirective,
8080
GraphQLSkipDirective,
8181
GraphQLDeferDirective,
82+
GraphQLStreamDirective,
8283
GraphQLDeprecatedDirective,
8384
// Constant Deprecation Reason
8485
DEFAULT_DEPRECATION_REASON,

src/type/schema.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class GraphQLSchema {
136136
__validationErrors: ?$ReadOnlyArray<GraphQLError>;
137137
// Referenced by execute()
138138
__experimentalDeferFragmentSpreads: boolean;
139+
__experimentalStream: boolean;
139140

140141
constructor(config: GraphQLSchemaConfig): void {
141142
// If this schema was built from a source known to be valid, then it may be
@@ -165,6 +166,7 @@ export class GraphQLSchema {
165166

166167
this.__experimentalDeferFragmentSpreads =
167168
config.experimentalDeferFragmentSpreads || false;
169+
this.__experimentalStream = config.experimentalStream || false;
168170
this._queryType = config.query;
169171
this._mutationType = config.mutation;
170172
this._subscriptionType = config.subscription;
@@ -327,6 +329,18 @@ export type GraphQLSchemaValidationOptions = {|
327329
* Default: false
328330
*/
329331
experimentalDeferFragmentSpreads?: boolean,
332+
333+
/**
334+
*
335+
* EXPERIMENTAL:
336+
*
337+
* If enabled, items from a plural fields with @stream directive
338+
* are not returned from the iniital query and each item is returned
339+
* in a patch after the initial result from the synchronous query.
340+
*
341+
* Default: false
342+
*/
343+
experimentalStream?: boolean,
330344
|};
331345

332346
export type GraphQLSchemaConfig = {|

src/utilities/__tests__/findBreakingChanges-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GraphQLSchema } from '../../type/schema';
77
import {
88
GraphQLSkipDirective,
99
GraphQLDeferDirective,
10+
GraphQLStreamDirective,
1011
GraphQLIncludeDirective,
1112
GraphQLDeprecatedDirective,
1213
} from '../../type/directives';
@@ -795,6 +796,7 @@ describe('findBreakingChanges', () => {
795796
GraphQLSkipDirective,
796797
GraphQLIncludeDirective,
797798
GraphQLDeferDirective,
799+
GraphQLStreamDirective,
798800
],
799801
});
800802

src/utilities/buildASTSchema.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
GraphQLSkipDirective,
5656
GraphQLIncludeDirective,
5757
GraphQLDeferDirective,
58+
GraphQLStreamDirective,
5859
GraphQLDeprecatedDirective,
5960
} from '../type/directives';
6061
import {
@@ -175,6 +176,10 @@ export function buildASTSchema(
175176
directives.push(GraphQLDeferDirective);
176177
}
177178

179+
if (!directives.some(directive => directive.name === 'stream')) {
180+
directives.push(GraphQLStreamDirective);
181+
}
182+
178183
if (!directives.some(directive => directive.name === 'deprecated')) {
179184
directives.push(GraphQLDeprecatedDirective);
180185
}

src/validation/__tests__/harness.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
GraphQLIncludeDirective,
1313
GraphQLSkipDirective,
1414
GraphQLDeferDirective,
15+
GraphQLStreamDirective,
1516
} from '../../type/directives';
1617
import {
1718
GraphQLInt,
@@ -364,6 +365,7 @@ export const testSchema = new GraphQLSchema({
364365
GraphQLIncludeDirective,
365366
GraphQLSkipDirective,
366367
GraphQLDeferDirective,
368+
GraphQLStreamDirective,
367369
new GraphQLDirective({
368370
name: 'onQuery',
369371
locations: ['QUERY'],

0 commit comments

Comments
 (0)