dotansimha / dotansimha/graphql-code-generator
[typescript-resolvers] Enums ValueMaps don't get generated anymore
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
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:
```ts
const resolvers: Resolvers = {
Sex: {
MALE: 0,
FEMALE: 1,
},
};
```
Unfortunately that will break the generated types because in `Resolvers` there will be no property set for the enum field.
[Older](https://github.com/dotansimha/graphql-code-generator/pull/1139) versions of the codegen generated a `ValueMap` for each enum so you could do something like this:
```ts
type EnumResolvers = {
Sex?: SexValueMap;
};
const resolvers: Resolvers & EnumResolvers = {
Sex: {
MALE: 0,
FEMALE: 1,
},
};
```
where the `ValueMap` was something like this:
```ts
type SexValueMap = {
MALE: Sex,
FEMALE: Sex,
};
```
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:
1. The `ValueMap` should map to the exact value:
```ts
type SexValueMap = {
MALE: Sex.MALE,
FEMALE: Sex.FEMALE,
};
```
2. The value map should be automatically added to the `Resolvers` type, in order to avoid doing the following:
```ts
type EnumResolvers = {
Sex?: SexValueMap;
};
const resolvers: Resolvers & EnumResolvers = {}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.