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

consider adding to typescript codegen config option enumSuffix

Open Eliav2 opened this issue 3 years ago • 4 comments

in my company we like to suffix graphql types with QLType so for example User schema type would become UserQLType. typescript type, however, the codegen also suffixes enum values which causes typescript errors.

expectations :

enum Rule {
    admin
    user
}

=>

export enum RuleQLType {
  Admin = 'admin',
  User = 'user'
}

Reality:

enum Rule {
    admin
    user
}

=>

export enum RuleQLType {
  AdminQLType = 'admin',
  UserQLType = 'user'
}

=> typescript error:

Types of property 'rule' are incompatible.
      Type 'rule' is not assignable to type 'RuleQLType'. 

enumPrefix exists, but not enumSuffix...

thanks

Eliav2 avatar May 10 '22 20:05 Eliav2

I also have the problem with suffixes added to enum, not only enum values but also enums in itself. Would be nice to opt out of it completely.

It should work in the same way as the enumPrefix option. It only makes sense!

Please consider adding this option. Thank you

Caruki avatar Jul 19 '22 12:07 Caruki

Hi we have exactly the same issue where enum properties also receive the suffix when we only want to suffix the enum name:

dream:

enum FruitEnum {
    Apple = 'APPLE'
}

reality:

enum FruitEnum {
    AppleEnum = 'APPLE'
}

Is there a workaround / way to address this?

surecloud-tstafford avatar Apr 13 '23 09:04 surecloud-tstafford

thanks @esfomeado! @dotansimha does this PR look good to merge?

surecloud-tstafford avatar Apr 14 '23 07:04 surecloud-tstafford

It seems that the above PR didn't actually achieve the requested effect, it suffixes the values but then doesn't suffix the enum itself. People here want to suffix the enum but not the values. Any possible workaround?

osdiab avatar Mar 11 '24 09:03 osdiab