From 0f35e775b8a710256aaeb28479959d9d4e2b320f Mon Sep 17 00:00:00 2001 From: Dotan Simha Date: Wed, 4 Nov 2020 19:29:08 +0200 Subject: [PATCH] Fix issues with incorrect naming when typesSuffix is used (#5038) --- .changeset/purple-bikes-call.md | 5 +++ .changeset/shaggy-brooms-enjoy.md | 5 +++ .../src/base-documents-visitor.ts | 4 +- .../operations/tests/ts-documents.spec.ts | 37 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .changeset/purple-bikes-call.md create mode 100644 .changeset/shaggy-brooms-enjoy.md diff --git a/.changeset/purple-bikes-call.md b/.changeset/purple-bikes-call.md new file mode 100644 index 00000000000..0718b77822c --- /dev/null +++ b/.changeset/purple-bikes-call.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/visitor-plugin-common': patch +--- + +Fix issues with incorrect naming of operation and variables when used with typesSuffix diff --git a/.changeset/shaggy-brooms-enjoy.md b/.changeset/shaggy-brooms-enjoy.md new file mode 100644 index 00000000000..56a453d60b0 --- /dev/null +++ b/.changeset/shaggy-brooms-enjoy.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/typescript-operations': patch +--- + +Fixed issues with incorrect naming when typesSuffix is used diff --git a/packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts b/packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts index f34e151ca04..27f783860f3 100644 --- a/packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts +++ b/packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts @@ -170,8 +170,9 @@ export class BaseDocumentsVisitor< const name = node.name && node.name.value; if (name) { - return this.convertName(node, { + return this.convertName(name, { useTypesPrefix: false, + useTypesSuffix: false, }); } @@ -179,6 +180,7 @@ export class BaseDocumentsVisitor< prefix: 'Unnamed_', suffix: '_', useTypesPrefix: false, + useTypesSuffix: false, }); } diff --git a/packages/plugins/typescript/operations/tests/ts-documents.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.spec.ts index 603b0d4f3db..3f3f9afefb6 100644 --- a/packages/plugins/typescript/operations/tests/ts-documents.spec.ts +++ b/packages/plugins/typescript/operations/tests/ts-documents.spec.ts @@ -3788,6 +3788,43 @@ describe('TypeScript Operations Plugin', () => { }); describe('Issues', () => { + it('#5001 - incorrect output with typeSuffix', async () => { + const testSchema = buildSchema(/* GraphQL */ ` + type Query { + user(id: ID!): User! + } + + type User { + id: ID! + username: String! + email: String! + } + `); + + const query = parse(/* GraphQL */ ` + query user { + user(id: 1) { + id + username + email + } + } + `); + + const config = { + typesSuffix: 'Type', + }; + + const { content } = await plugin(testSchema, [{ location: '', document: query }], config, { + outputFile: 'graphql.ts', + }); + + expect(content).not.toContain('UserTypeQueryVariablesType'); + expect(content).not.toContain('UserTypeQueryType'); + expect(content).toContain('UserQueryVariablesType'); + expect(content).toContain('UserQueryType'); + }); + it('#3064 - fragments over interfaces causes issues with fields', async () => { const testSchema = buildSchema(/* GraphQL */ ` interface Venue {