Closed chamatt closed 1 month ago
Sorry, I'll post the other threads here later that are related to this, but we've explained in other discussions/issues why this isn't done.
tl;dr enums aren't types and we don't generate runtime code. Even if we did, enums are a poor choice for GraphQL enums or in general for API values. Sorry 😅❤️
Summary
Enums is a feature of graphql, and for most codebases the enum type is widely used within the codebase for a lot of things.
Let's say we have the following Enum in our graphql schema:
Then we want to use it in our app to perform a calculation:
But because gql.tada transforms the enums into ("DOG" | "CAT" | "BIRD"), this code no longer works. (Argument of type '"DOG"' is not assignable to parameter of type 'AnimalType'.ts(2345))
And we would either have to refactor it to:
Or give up the enum, and grab it directly from a specific graphql query ResultOf<>, which would kill the reusability of a shared function.
I've seem a topic about this, but the solution given was to manually add the enums to the scalars object, but since it's generated by the schema file, someone would have to remember to add/remove an enum everytime a new one is created.
Proposed Solution
Create a configuration to keep enums as is, instead of turning into a string union