dotansimha / dotansimha/graphql-code-generator
Enum types are mapped incorrectly in `ResolversTypes`
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Which packages are impacted by your issue?
@graphql-codegen/typescript-resolvers, @graphql-codegen/typescript
### Describe the bug
When the TypeScript enum and the GraphQL enum aren't named identically the generated resolver types are invalid and will not compile.
### Your Example Website or App
https://codesandbox.io/s/graphql-codegen-enum-types-wt98s9?file=/resolvers.ts
### Steps to Reproduce the Bug or Issue
With the following config
```json
{
"enumValues": {
"MyGqlEnum": "@swydo/foo#MyTsEnum"
}
}
```
the following is generated:
```typescript
import { MyTsEnum as MyGqlEnum } from '@swydo/collections';
export type ResolversTypes = {
MyGqlEnum: MyTsEnum;
}
```
Notice how the type is imported and immediately mapped to the GraphQL enum name, but then it is incorrectly assigned
in ResolversTypes (`MyTsEnum` is not defined).
### Expected behavior
The TypeScript enum is correctly mapped to the GraphQL enum.
### Screenshots or Videos
_No response_
### Platform
- OS: macOS
- NodeJS: 18.14.0
- `graphql` version:
"graphql": "16.6.0",
- `@graphql-codegen/*` version(s):
"@graphql-codegen/cli": "3.2.1",
"@graphql-codegen/near-operation-file-preset": "2.5.0",
"@graphql-codegen/typescript": "3.0.1",
"@graphql-codegen/typescript-resolvers": "3.1.0",
### Codegen Config File
```typescript
import { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
schema: "schema.graphql",
documents: "document.graphql",
generates: {
"types.ts": { plugins: ["typescript", "typescript-operations"] },
"resolvers.ts": {
config: {
mapperTypeSuffix: "Model",
namingConvention: {
typeNames: "change-case-all#pascalCase",
enumValues: "change-case-all#upperCase"
},
mappers: {},
enumValues: {
MyGqlEnum: "./MyTsEnum#MyTsEnum"
}
},
plugins: ["typescript", "typescript-resolvers"]
}
}
};
export default config;
```
### Additional context
It looks like some earlier version generated the following import:
```
import { MyTsEnum } from './MyTsEnum';
import MyGqlEnum = MyTsEnum;
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.