dotansimha / dotansimha/graphql-code-generator
Inconsistent enum type name conversion
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Which packages are impacted by your issue?
@graphql-codegen/visitor-plugin-common, @graphql-codegen/typescript
### Describe the bug
Enum type name case conversion is inconsistent when the enum values are different from their names.
### Your Example Website or App
https://stackblitz.com/edit/github-kqnrfg-12jsvd?file=schema.ts,types.ts
### Steps to Reproduce the Bug or Issue
The stackblitz link shows the issue without needing any interaction. These are the required conditions:
1. Have an enum type with a name that would be converted by the codegen config e.g. `AAA` with `change-case-all#pascalCase`.
2. Specify custom enum values that do not match their name e.g. `X: { value: 1 }`
3. Generate types for the schema.
### Expected behavior
I expect the converted enum name of `Aaa` to be used where it is referenced in the `Query` fields rather than the original `AAA` name.
### Screenshots or Videos
_No response_
### Platform
- `@graphql-codegen/typescript` version: 2.8.0
- `@graphql-codegen/visitor-plugin-common` version: 2.13.0
### Codegen Config File
_No response_
### Additional context
I believe the issue is that the non-matching enum values causes `parseEnumValues` to populate an entry for that enum type in the dynamic config here:
https://github.com/dotansimha/graphql-code-generator/blob/e2ca85730f5d1f0eb6b15ba15547ce7d389f364e/packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts#L488-L492
This causes `_getTypeForNode` to shortcut here:
https://github.com/dotansimha/graphql-code-generator/blob/e2ca85730f5d1f0eb6b15ba15547ce7d389f364e/packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts#L974-L976
and that bypasses the name conversion.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.