UNPKG

2.16 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.useDeferStream = void 0;
4const graphql_1 = require("graphql");
5const utils_1 = require("@graphql-tools/utils");
6const defer_stream_directive_label_js_1 = require("./validations/defer-stream-directive-label.js");
7const defer_stream_directive_on_root_field_js_1 = require("./validations/defer-stream-directive-on-root-field.js");
8const overlapping_fields_can_be_merged_js_1 = require("./validations/overlapping-fields-can-be-merged.js");
9const stream_directive_on_list_field_js_1 = require("./validations/stream-directive-on-list-field.js");
10function useDeferStream() {
11 return {
12 onSchemaChange: ({ schema, replaceSchema, }) => {
13 const directives = [];
14 const deferInSchema = schema.getDirective('defer');
15 if (deferInSchema == null) {
16 directives.push(utils_1.GraphQLDeferDirective);
17 }
18 const streamInSchema = schema.getDirective('stream');
19 if (streamInSchema == null) {
20 directives.push(utils_1.GraphQLStreamDirective);
21 }
22 if (directives.length) {
23 replaceSchema(new graphql_1.GraphQLSchema({
24 ...schema.toConfig(),
25 directives: [...schema.getDirectives(), ...directives],
26 }));
27 }
28 },
29 onValidate: ({ params, addValidationRule, }) => {
30 // Just to make TS happy because rules are always defined by useEngine.
31 params.rules = params.rules || [];
32 params.rules = params.rules.filter((rule) => rule.name !== 'OverlappingFieldsCanBeMergedRule');
33 addValidationRule(overlapping_fields_can_be_merged_js_1.OverlappingFieldsCanBeMergedRule);
34 addValidationRule(defer_stream_directive_label_js_1.DeferStreamDirectiveLabelRule);
35 addValidationRule(defer_stream_directive_on_root_field_js_1.DeferStreamDirectiveOnRootFieldRule);
36 addValidationRule(stream_directive_on_list_field_js_1.StreamDirectiveOnListFieldRule);
37 },
38 };
39}
40exports.useDeferStream = useDeferStream;