Skip to content

Commit 609aff6

Browse files
robrichardlilianammmatos
authored andcommitted
set up new directive
1 parent 815896d commit 609aff6

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: $ReadOnly<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;
@@ -320,6 +322,18 @@ export type GraphQLSchemaValidationOptions = {|
320322
* Default: false
321323
*/
322324
experimentalDeferFragmentSpreads?: boolean,
325+
326+
/**
327+
*
328+
* EXPERIMENTAL:
329+
*
330+
* If enabled, items from a plural fields with @stream directive
331+
* are not returned from the iniital query and each item is returned
332+
* in a patch after the initial result from the synchronous query.
333+
*
334+
* Default: false
335+
*/
336+
experimentalStream?: boolean,
323337
|};
324338

325339
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
@@ -17,6 +17,7 @@ import {
1717
GraphQLSkipDirective,
1818
GraphQLIncludeDirective,
1919
GraphQLDeferDirective,
20+
GraphQLStreamDirective,
2021
GraphQLDeprecatedDirective,
2122
} from '../type/directives';
2223

@@ -110,6 +111,10 @@ export function buildASTSchema(
110111
directives.push(GraphQLDeferDirective);
111112
}
112113

114+
if (!directives.some(directive => directive.name === 'stream')) {
115+
directives.push(GraphQLStreamDirective);
116+
}
117+
113118
if (!directives.some(directive => directive.name === 'deprecated')) {
114119
directives.push(GraphQLDeprecatedDirective);
115120
}

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)