graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

[typescript] Opt out of suffix for enum value keys

Open lee-alexander opened this issue 5 years ago • 2 comments

Is your feature request related to a problem? Please describe. It's a bit odd that suffixes are applied to enum values in addition to the enum itself (when using typesSuffix):

export enum RoleSuffix {
  UserSuffix = 'USER',
  AdminSuffix = 'ADMIN'
}

Normally the suffix is useful to disambiguate the overall type when importing and using it in files, but there is not much benefit to having a suffix on the values themselves in most cases (UserSuffix, for example).

Describe the solution you'd like Add a flag to opt out of this behavior. suffixEnumValues true/false

lee-alexander avatar Aug 18 '21 22:08 lee-alexander

This issue bugs us as well and I can contribute an enhancement for it. I checked the code and it seems that the useTypesPrefix is ignored for enum values.

I see 2 options to implement this and keeping it consistent:

  1. Just ignore the suffix for enum values. This would be a breaking change.
  2. Add suffixEnumValues and prefixEnumValues options with defaults matching the current behaviour.

Personally, I am fine with both approaches. I would prefer Option 1 if breaking a bit the generated code is OK. I don't think anyone would want to add suffix or prefix to their enum values. And I would lean on simpler configuration until there is an actual need for that.

Which approach do you think makes more sense? /cc @n1ru4l

ibratoev avatar Mar 16 '22 07:03 ibratoev

Following this PR: https://github.com/dotansimha/graphql-code-generator/pull/1553 Maybe, it is really Option 1 that I should go with...

ibratoev avatar Mar 16 '22 07:03 ibratoev