When using a custom namingConvention function to add a suffix for generated types, the operations' name does not match with the respective value inside TypedDocumentNode. See "Expected behavior" section for more details.
It looks like a redundant suffix is being added in handleAnonymousOperation:
Take a look at the errors inside ~/__generated__/gql/graphql.ts
Or if you prefer, you can create a new project with the provided codegen.ts and run graphql-codegen.
Expected behavior
If I don't specify a namingConvention to add a suffix, this is how the generated code would look like:
export type UserQueryVariables = Exact<{ ... }>;
export type UserQuery = { ... };
export const UserDocument = { ... } as unknown as DocumentNode<UserQuery, UserQueryVariables>;
I expected that after adding the suffix, it would look like this:
export type UserQueryVariablesCustomSuffix = Exact<{ ... }>;
export type UserQueryCustomSuffix = { ... };
export const UserDocumentCustomSuffix = { ... } as unknown as DocumentNode<UserQueryCustomSuffix, UserQueryVariablesCustomSuffix>;
However, this is the result:
// šļø This does not match with DocumentNode in UserDocumentCustomSuffix
export type UserCustomSuffixQueryVariablesCustomSuffix = Exact<{ ... }>; // <-- š
// šļø This does not match with DocumentNode in UserDocumentCustomSuffix
export type UserCustomSuffixQueryCustomSuffix = { ... };
export const UserDocumentCustomSuffix = { ... } as unknown as DocumentNode<UserQueryCustomSuffix, UserQueryVariablesCustomSuffix>;
Screenshots or Videos
Platform
OS: Linux 6.8 Fedora Linux 40 (Workstation Edition)
Which packages are impacted by your issue?
@graphql-codegen/visitor-plugin-common
Describe the bug
When using a custom
namingConvention
function to add a suffix for generated types, the operations' name does not match with the respective value inside TypedDocumentNode. See "Expected behavior" section for more details.It looks like a redundant suffix is being added in
handleAnonymousOperation
:https://github.com/dotansimha/graphql-code-generator/blob/9af9ce215e210241b1ae9e8b7e3f60e3f9f10aa7/packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts#L218-L234
It's then added again in few lines underneath:
https://github.com/dotansimha/graphql-code-generator/blob/9af9ce215e210241b1ae9e8b7e3f60e3f9f10aa7/packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts#L285-L293
Your Example Website or App
https://stackblitz.com/edit/gql-codgen-13f1zd
Steps to Reproduce the Bug or Issue
npm run generate
(optional)~/__generated__/gql/graphql.ts
Or if you prefer, you can create a new project with the provided
codegen.ts
and run graphql-codegen.Expected behavior
If I don't specify a
namingConvention
to add a suffix, this is how the generated code would look like:I expected that after adding the suffix, it would look like this:
However, this is the result:
Screenshots or Videos
Platform
graphql
version: 16.8.2@graphql-codegen/cli
version: 5.0.2Codegen Config File