1 | import { buildASTSchema } from 'graphql';
|
2 | import { getDocumentNodeFromSchema } from './print-schema-with-directives.js';
|
3 | function buildFixedSchema(schema, options) {
|
4 | const document = getDocumentNodeFromSchema(schema);
|
5 | return buildASTSchema(document, {
|
6 | ...(options || {}),
|
7 | });
|
8 | }
|
9 | export function fixSchemaAst(schema, options) {
|
10 |
|
11 | let schemaWithValidAst = undefined;
|
12 | if (!schema.astNode || !schema.extensionASTNodes) {
|
13 | schemaWithValidAst = buildFixedSchema(schema, options);
|
14 | }
|
15 | if (!schema.astNode && schemaWithValidAst?.astNode) {
|
16 | schema.astNode = schemaWithValidAst.astNode;
|
17 | }
|
18 | if (!schema.extensionASTNodes && schemaWithValidAst?.astNode) {
|
19 | schema.extensionASTNodes = schemaWithValidAst.extensionASTNodes;
|
20 | }
|
21 | return schema;
|
22 | }
|