From a32fc158c28497b0e12d864bcf01aa54992c4ebb Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Sat, 29 Jun 2024 14:37:30 +1000 Subject: [PATCH] Allow .graphqls as extension for schema-ast --- .changeset/forty-ears-rule.md | 5 +++++ packages/plugins/other/schema-ast/src/index.ts | 2 +- .../other/schema-ast/tests/schema-ast.spec.ts | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .changeset/forty-ears-rule.md diff --git a/.changeset/forty-ears-rule.md b/.changeset/forty-ears-rule.md new file mode 100644 index 00000000000..97fdfe3c9cb --- /dev/null +++ b/.changeset/forty-ears-rule.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/schema-ast': minor +--- + +Allow .graphqls as schema extension diff --git a/packages/plugins/other/schema-ast/src/index.ts b/packages/plugins/other/schema-ast/src/index.ts index c696f954f2d..2f593ce06e5 100644 --- a/packages/plugins/other/schema-ast/src/index.ts +++ b/packages/plugins/other/schema-ast/src/index.ts @@ -130,7 +130,7 @@ export const validate: PluginValidateFn = async ( ) => { const singlePlugin = allPlugins.length === 1; - const allowedExtensions = ['.graphql', '.gql']; + const allowedExtensions = ['.graphql', '.gql', '.graphqls']; const isAllowedExtension = allowedExtensions.includes(extname(outputFile)); if (singlePlugin && !isAllowedExtension) { diff --git a/packages/plugins/other/schema-ast/tests/schema-ast.spec.ts b/packages/plugins/other/schema-ast/tests/schema-ast.spec.ts index 51637da84bc..36e8e97631d 100644 --- a/packages/plugins/other/schema-ast/tests/schema-ast.spec.ts +++ b/packages/plugins/other/schema-ast/tests/schema-ast.spec.ts @@ -22,7 +22,7 @@ describe('Schema AST', () => { throw new Error(SHOULD_THROW_ERROR); } catch (e) { expect(e.message).not.toBe(SHOULD_THROW_ERROR); - expect(e.message).toBe('Plugin "schema-ast" requires extension to be ".graphql" or ".gql"!'); + expect(e.message).toBe('Plugin "schema-ast" requires extension to be ".graphql" or ".gql" or ".graphqls"!'); } }); @@ -73,6 +73,21 @@ describe('Schema AST', () => { expect(true).toBeFalsy(); } }); + + it('Should allow .graphqls extension when its the only plugin', async () => { + const fileName = 'output.graphqls'; + const plugins: Types.ConfiguredPlugin[] = [ + { + 'schema-ast': {}, + }, + ]; + + try { + await validate(null, null, null, fileName, plugins); + } catch (e) { + expect(true).toBeFalsy(); + } + }); }); describe('Output', () => { const typeDefs = /* GraphQL */ `