You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if support for enums with custom internal values would be re-introduced, but in my opinion it should be done in a slightly different way:
dotansimha
changed the title
[Regression] enums ValueMaps don't get generated anymore
[typescript-resolvers][Regression] enums ValueMaps don't get generated anymore
Mar 11, 2020
dotansimha
changed the title
[typescript-resolvers][Regression] enums ValueMaps don't get generated anymore
[typescript-resolvers] Enums ValueMaps don't get generated anymore
Mar 11, 2020
Another problem I have is when i'm trying to use the variable in for example if. sex: Sex
and I say if(sex === 'male') gives type error because in generated schema its defined sex === 'MALE'
is there any solution to this?
You want to use if (sex === Sex.MALE) otherwise you will lose most of the benefits anyway.
Exactly right now I'm asserting type to values for example I'm saying if(sex === ('male' as Sex)) and I know its very bad but i don't have any other solution
Apollo allows you to customize the internal values of your GraphQL enums: https://www.apollographql.com/docs/apollo-server/schema/scalars-enums/
That means that in you resolvers you will do something like this:
Unfortunately that will break the generated types because in
Resolvers
there will be no property set for the enum field.Older versions of the codegen generated a
ValueMap
for each enum so you could do something like this:where the
ValueMap
was something like this:Since codegen v1 this doesn't work anymore.
It would be nice if support for enums with custom internal values would be re-introduced, but in my opinion it should be done in a slightly different way:
ValueMap
should map to the exact value:Resolvers
type, in order to avoid doing the following:The text was updated successfully, but these errors were encountered: