1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.useDeferStream = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | const utils_1 = require("@graphql-tools/utils");
|
6 | const defer_stream_directive_label_js_1 = require("./validations/defer-stream-directive-label.js");
|
7 | const defer_stream_directive_on_root_field_js_1 = require("./validations/defer-stream-directive-on-root-field.js");
|
8 | const overlapping_fields_can_be_merged_js_1 = require("./validations/overlapping-fields-can-be-merged.js");
|
9 | const stream_directive_on_list_field_js_1 = require("./validations/stream-directive-on-list-field.js");
|
10 | function 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 |
|
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 | }
|
40 | exports.useDeferStream = useDeferStream;
|