Can we have utility from tada
can return enum
object
#263
-
i know for now tada support infer typings for export type Permissions = ReturnType<typeof graphql.scalar<'Permission'>>; but if here have method to like const Permissions = graphql.scalar<'Permission'> or somethings
// asume that the typings `Permission` have over 100+, we should make data automatically generated it that's better we want get a vaiables is there any suggestins? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Don't do this is my suggestion. This may seem like a great idea at first, however, there are well documented resources on the drawbacks of enums in TypeScript. One could of course reach for const enums, but that explicitly excludes the case you're speaking about. You can since a recent version replace the types that Lastly, I repeatedly see patterns where people reach for GraphQL unions to make human-readable string mapping, instead of simply returning this from their GraphQL APIs as lists of object types, making their UI less GraphQL-driven and more client-driven. |
Beta Was this translation helpful? Give feedback.
-
thanks for you explanation, haha agree |
Beta Was this translation helpful? Give feedback.
Don't do this is my suggestion.
This may seem like a great idea at first, however, there are well documented resources on the drawbacks of enums in TypeScript. One could of course reach for const enums, but that explicitly excludes the case you're speaking about.
That's kind of for good reason. Unions of string literals are pretty forward-compatible, but enums are not and give off the impression that you can have exhaustive checks. But in the spirit of GraphQL backwards-compatibility enums are just not a great choice for this.
You can since a recent version replace the types that
gql.tada
uses for enums using thescalars
option, e.g. you can override the type for a given enum type with a …