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
Fragment enum fields aren't compatible with Type enum fields #2326
Comments
Hi @jkillian ! |
Hi @dotansimha, thanks for the response!
Yes, I think this would work, but we have many places in our codebase where we reference the enums, using the example from above, things like,
I'd actually argue that using an
Let me know if all this makes sense! |
There's actually a third option, which would be to export both a export const Role = {
USER: 'USER',
ADMIN: 'ADMIN'
} as const;
export type Role = keyof typeof Role; I actually think that's kind of a nice option! It gives you the best of both worlds in TypeScript in my opinion. |
Fixed in 1.6.0 |
Amazing! I look forward to trying it out in a few days. Thank you again for all your hard work on the project @dotansimha! |
Describe the bug
In the generated TypeScript types for a GraphQL schema, enum fields are typed as
field: EnumType
. However, in fragments, they're typed as a union of string literals:field: "VAL1" | "VAL2";
This means that the two types are not assignable to each other which can cause a variety of challenges in application code.The issue is illustrated in this screenshot:
Note: I mentioned the same issue here, but decided it would be cleaner to just open a new issue than tack on to a long pre-existing one. Sorry for the noise!
To Reproduce
Steps to reproduce the behavior:
codegen.yml
config file:Expected behavior
The generated fragment should use the enum type instead of being a union of literals:
Environment:
@graphql-codegen/...
: 1.5.0The text was updated successfully, but these errors were encountered: