-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
apollo client:codegen Option for different TypeScript enum output #1044
Comments
Related:
|
+1, having an enum is annoying for me. I don't want to import the enum and to Enum.Value, I just want to use string literals, it's as safe as enums and works nicely |
#247 was a mistake IMO. String enums should only really be used when you want the underlying string value to be opaque, and that isn't a feature that GraphQL can provide. This would maybe be a good idea if you could produce stable key names, but the key names are going to change just as often as the string values themselves, so there's no point. |
String enums still have a slight advantage in that you can find all usages of it. String constants actually can be searched by "find all usages", which was a nice surprise (:tada:), but typescript can't distinguish "intentional" uses from "coincidental" uses of a given string constant -- the string enums work to disambiguate them, especially if there are multiple different enums in your schema that happen to partially overlap in some of the values; it would be good to know which enum is being referred to when the value appears in code. I think this might be mitigated by the planned "unique types" feature, but I haven't seen if it can be made to work for this use case. |
These also work better if you have a js codebase and are using |
I've fixed this in #1750 🙄 |
Currently, the following GraphQL type
generates the following TypeScript type
I would like to have the option to generate the following type instead:
This definition provides the same safety, but is more efficient and works better with TypeScript structural typing.
Unrelated: consider generating
const enum
instead ofenum
.The text was updated successfully, but these errors were encountered: