1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.extractHashFromSchema = exports.hasFederationSpec = exports.getSkipDocumentsValidationOption = exports.shouldValidateDocumentsAgainstSchema = exports.shouldValidateDuplicateDocuments = exports.pickFlag = exports.prioritize = exports.isObjectMap = void 0;
|
4 | const utils_1 = require("@graphql-tools/utils");
|
5 | const graphql_1 = require("graphql");
|
6 | function isObjectMap(obj) {
|
7 | return obj && typeof obj === 'object' && !Array.isArray(obj);
|
8 | }
|
9 | exports.isObjectMap = isObjectMap;
|
10 | function prioritize(...values) {
|
11 | const picked = values.find(val => typeof val === 'boolean');
|
12 | if (typeof picked !== 'boolean') {
|
13 | return values[values.length - 1];
|
14 | }
|
15 | return picked;
|
16 | }
|
17 | exports.prioritize = prioritize;
|
18 | function pickFlag(flag, config) {
|
19 | return isObjectMap(config) ? config[flag] : undefined;
|
20 | }
|
21 | exports.pickFlag = pickFlag;
|
22 | function shouldValidateDuplicateDocuments(skipDocumentsValidationOption) {
|
23 |
|
24 | if (skipDocumentsValidationOption === true) {
|
25 | return false;
|
26 | }
|
27 |
|
28 | if (typeof skipDocumentsValidationOption === 'object' && skipDocumentsValidationOption.skipDuplicateValidation) {
|
29 | return false;
|
30 | }
|
31 |
|
32 | return true;
|
33 | }
|
34 | exports.shouldValidateDuplicateDocuments = shouldValidateDuplicateDocuments;
|
35 | function shouldValidateDocumentsAgainstSchema(skipDocumentsValidationOption) {
|
36 |
|
37 | if (skipDocumentsValidationOption === true) {
|
38 | return false;
|
39 | }
|
40 |
|
41 | if (typeof skipDocumentsValidationOption === 'object' && skipDocumentsValidationOption.skipValidationAgainstSchema) {
|
42 | return false;
|
43 | }
|
44 |
|
45 | return true;
|
46 | }
|
47 | exports.shouldValidateDocumentsAgainstSchema = shouldValidateDocumentsAgainstSchema;
|
48 | function getSkipDocumentsValidationOption(options) {
|
49 |
|
50 | if (options.skipDocumentsValidation) {
|
51 | return options.skipDocumentsValidation;
|
52 | }
|
53 |
|
54 | const flagFromConfig = pickFlag('skipDocumentsValidation', options.config);
|
55 | if (flagFromConfig) {
|
56 | return flagFromConfig;
|
57 | }
|
58 | return false;
|
59 | }
|
60 | exports.getSkipDocumentsValidationOption = getSkipDocumentsValidationOption;
|
61 | const federationDirectives = ['key', 'requires', 'provides', 'external'];
|
62 | function hasFederationSpec(schemaOrAST) {
|
63 | if ((0, graphql_1.isSchema)(schemaOrAST)) {
|
64 | return federationDirectives.some(directive => schemaOrAST.getDirective(directive));
|
65 | }
|
66 | if ((0, utils_1.isDocumentNode)(schemaOrAST)) {
|
67 | return schemaOrAST.definitions.some(def => def.kind === graphql_1.Kind.DIRECTIVE_DEFINITION && federationDirectives.includes(def.name.value));
|
68 | }
|
69 | return false;
|
70 | }
|
71 | exports.hasFederationSpec = hasFederationSpec;
|
72 | function extractHashFromSchema(schema) {
|
73 | var _a;
|
74 | schema.extensions || (schema.extensions = {});
|
75 | return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
|
76 | }
|
77 | exports.extractHashFromSchema = extractHashFromSchema;
|