New config option which would generate Enum Values in schema instead of only keys #1770
Labels
Community 👨👧
Something initiated by a community
Discussion 💬
Brainstorm about the idea
Enhancement 🆕
New feature or request
At the moment by default type-graphql generates the enums in the schema files only using their keys e.g:
While this is ok in most cases, since the values itself is passed to the code not the key, it covers most of the cases.
But...
A lot of developers use tools like GraphQl CodeGen to generate their types for Frontend from graphql schema, so that they do not need to write in UI these twice and just import from the generated file.
Now to use these generated types is impossible because code-generator knows from schema only the Keys of these enums and asumes the values are the same as the keys
And Given that GraphQL also allows different values for the enums I think we should add a Optional not breaking option to type-graphql to let the developer select if they want a different behavior and having the values in the gql schema as well, so that when they generate the TS types it gets generated correctly with values
Now a lot of peoples will say well why don't you use a monorepo and keep the types as a separate lib and the I'm port in UI as well
well this is impossible because the generated enums in schema as I said has only keys and when you send a value to as variable it expects this exact format but the enum in TS will resolve to its value
and if you have in TS something like
If you'll try to use this as gql variable it won't work even if that is what you provided to type-graphql to register
The text was updated successfully, but these errors were encountered: