Skip to content

Commit be6fdb8

Browse files
committed
fix(utils): bring back breaking change for fixSchemaAst
1 parent a03a045 commit be6fdb8

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

.changeset/wild-owls-drop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': patch
3+
---
4+
5+
fix(utils): bring back breaking change for fixSchemaAst

packages/utils/src/fixSchemaAst.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { GraphQLSchema, BuildSchemaOptions, buildASTSchema } from 'graphql';
2+
import { SchemaPrintOptions } from './types';
3+
import { getDocumentNodeFromSchema } from './print-schema-with-directives';
4+
5+
function buildFixedSchema(schema: GraphQLSchema, options: BuildSchemaOptions & SchemaPrintOptions) {
6+
const document = getDocumentNodeFromSchema(schema);
7+
return buildASTSchema(document, {
8+
...(options || {}),
9+
});
10+
}
11+
12+
export function fixSchemaAst(schema: GraphQLSchema, options: BuildSchemaOptions & SchemaPrintOptions) {
13+
// eslint-disable-next-line no-undef-init
14+
let schemaWithValidAst: GraphQLSchema | undefined = undefined;
15+
if (!schema.astNode || !schema.extensionASTNodes) {
16+
schemaWithValidAst = buildFixedSchema(schema, options);
17+
}
18+
19+
if (!schema.astNode && schemaWithValidAst?.astNode) {
20+
schema.astNode = schemaWithValidAst.astNode;
21+
}
22+
if (!schema.extensionASTNodes && schemaWithValidAst?.astNode) {
23+
schema.extensionASTNodes = schemaWithValidAst.extensionASTNodes;
24+
}
25+
return schema;
26+
}

packages/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ export * from './comments';
4646
export * from './collectFields';
4747
export * from './inspect';
4848
export * from './memoize';
49+
export * from './fixSchemaAst';

0 commit comments

Comments
 (0)