1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.fixSchemaAst = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | const print_schema_with_directives_js_1 = require("./print-schema-with-directives.js");
|
6 | function buildFixedSchema(schema, options) {
|
7 | const document = (0, print_schema_with_directives_js_1.getDocumentNodeFromSchema)(schema);
|
8 | return (0, graphql_1.buildASTSchema)(document, {
|
9 | ...(options || {}),
|
10 | });
|
11 | }
|
12 | function fixSchemaAst(schema, options) {
|
13 |
|
14 | let schemaWithValidAst = undefined;
|
15 | if (!schema.astNode || !schema.extensionASTNodes) {
|
16 | schemaWithValidAst = buildFixedSchema(schema, options);
|
17 | }
|
18 | if (!schema.astNode && schemaWithValidAst?.astNode) {
|
19 | schema.astNode = schemaWithValidAst.astNode;
|
20 | }
|
21 | if (!schema.extensionASTNodes && schemaWithValidAst?.astNode) {
|
22 | schema.extensionASTNodes = schemaWithValidAst.extensionASTNodes;
|
23 | }
|
24 | return schema;
|
25 | }
|
26 | exports.fixSchemaAst = fixSchemaAst;
|