Skip to content

Commit

Permalink
Fix issues with incorrect naming when typesSuffix is used (#5038)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Nov 4, 2020
1 parent 9f2a4e2 commit 0f35e77
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/purple-bikes-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/visitor-plugin-common': patch
---

Fix issues with incorrect naming of operation and variables when used with typesSuffix
5 changes: 5 additions & 0 deletions .changeset/shaggy-brooms-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-operations': patch
---

Fixed issues with incorrect naming when typesSuffix is used
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,17 @@ export class BaseDocumentsVisitor<
const name = node.name && node.name.value;

if (name) {
return this.convertName(node, {
return this.convertName(name, {
useTypesPrefix: false,
useTypesSuffix: false,
});
}

return this.convertName(this._unnamedCounter++ + '', {
prefix: 'Unnamed_',
suffix: '_',
useTypesPrefix: false,
useTypesSuffix: false,
});
}

Expand Down
37 changes: 37 additions & 0 deletions packages/plugins/typescript/operations/tests/ts-documents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0f35e77

Please sign in to comment.