dotansimha / dotansimha/graphql-code-generator
Typescript: generate *both* enums and types?
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Feature request: some way to expose GraphQL enums as both types _and_ enums.
**Context**
I'm updating an old codebase that was using a combination of apollo-codegen and an early version of graphql-code-generator.
In the old system, one generator produced the equivalent of today's `enumsAsTypes: true`, and the other `enumsAsTypes: false`. The codebase has come to rely on having both available.
**Describe the solution you'd like**
I'd like some way to generate both.
**Describe alternatives you've considered**
1) Generate enums, and try to derive a union type using TypeScript.
so, e.g. generate `enum Foo { Bar = "bar", Baz = "baz" }`, and then try to implement `type EnumValuesOf` to produce a type of `"bar" | "baz"`.
I didn't get very far with this.
2) Generate separate files with `enumsAsTypes: true` and `enumsAsTypes: false`.
This could work, but duplicates everything that's not an enum.
Perhaps I could tell the generator to emit a file that has _only_ enums in it? Then I'd emit one file with everything (and `enumsAsTypes:false`), and then emit a second enums-only file with `enumsAsTypes:true`.
**Other ideas?**
I'd be interested to hear other approaches to this problem, especially if they're achievable with the current versions of Typescript and graphql-code-generator ;)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.