question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Enums keys a PascalCase by default

See original GitHub issue

If you take a look at typescript docs, you can see that Enums are PascalCase. But here when you have enum generated, they are taken as is from the schema. What do you think to generate left side as PascalCase while right side to be the actual value from the schema enum definition?

We have a huge codebase and many enums are already PascalCase having them mixed is rather a pain in the ass.

Schema:

enum SomeEnum {
  COOL
  NOT_COOL
}

Current:

enum SomeEnum {
  COOL = "COOL",
  NOT_COOL = "NOT_COOL"
}

Proposed:

enum SomeEnum {
  Cool = "COOL",
  NotCool = "NOT_COOL"
}

What do you think? Maybe an option?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
NickTomlincommented, Dec 17, 2019

I recently encountered this when I needed to map enums in my schema to enums owned by another service. To preserve the enum values as-is (e.g. MY_ENUM_VALUE -> MY_ENUM_VALUE) you can use the namingConventions config in codegen:

config:
  namingConvention:
    enumValues: keep

If that still doesn’t do what you’d like, you should be able to provide a custom mapper

6reactions
lostpebblecommented, Dec 26, 2018

Is there any way to prevent this @dotansimha ? This change has messed up my rather large code base now cause all Enums have changed…

EDIT: This is not the first time this has happened with this project (The last pascal-case things caused big headaches too). Please consider making changes backwards-compatible, as in at least always provide an option to keep previous behaviour. If you have done so for this change, I appreciate it- but as of now I can’t find any documentation on how to keep the old behaviour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handbook - Enums - TypeScript
Using enums can make it easier to document intent, or create a set of distinct cases. TypeScript provides both numeric and string-based enums....
Read more >
How do I make Graphql Code Generator for typescript make ...
You can set the naming convention in config in your codegen.yml file. config: namingConvention: change-case-all#pascalCase.
Read more >
Swift enums: An overview with examples - LogRocket Blog
To define an enum in Swift, use the keyword enum followed by the name of the enum. The name of an enum in...
Read more >
A Complete Guide to Enums in TypeScript | by Jennifer Fu
By default, enums are numeric enums, i.e. Fruit.Apple is 0, Fruit.Orange is 1, Fruit.Peach is 2, and Fruit.Pear is 3.
Read more >
Is it okay to go against all-caps naming for enums to make ...
If you want the guaranteed default behavior of enum names, use name() . I don't find it "tempting" at all to rely on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found