Skip to content

Commit

Permalink
fix(utils): bring back breaking change for fixSchemaAst
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Aug 31, 2021
1 parent a03a045 commit be6fdb8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-owls-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

fix(utils): bring back breaking change for fixSchemaAst
26 changes: 26 additions & 0 deletions packages/utils/src/fixSchemaAst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { GraphQLSchema, BuildSchemaOptions, buildASTSchema } from 'graphql';
import { SchemaPrintOptions } from './types';
import { getDocumentNodeFromSchema } from './print-schema-with-directives';

function buildFixedSchema(schema: GraphQLSchema, options: BuildSchemaOptions & SchemaPrintOptions) {
const document = getDocumentNodeFromSchema(schema);
return buildASTSchema(document, {
...(options || {}),
});
}

export function fixSchemaAst(schema: GraphQLSchema, options: BuildSchemaOptions & SchemaPrintOptions) {
// eslint-disable-next-line no-undef-init
let schemaWithValidAst: GraphQLSchema | undefined = undefined;
if (!schema.astNode || !schema.extensionASTNodes) {
schemaWithValidAst = buildFixedSchema(schema, options);
}

if (!schema.astNode && schemaWithValidAst?.astNode) {
schema.astNode = schemaWithValidAst.astNode;
}
if (!schema.extensionASTNodes && schemaWithValidAst?.astNode) {
schema.extensionASTNodes = schemaWithValidAst.extensionASTNodes;
}
return schema;
}
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ export * from './comments';
export * from './collectFields';
export * from './inspect';
export * from './memoize';
export * from './fixSchemaAst';

1 comment on commit be6fdb8

@vercel
Copy link

@vercel vercel bot commented on be6fdb8 Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.