dotansimha / dotansimha/graphql-code-generator
Using `enumValues` with `typescript-resolvers` is incompatible with `verbatimModuleSyntax`
- 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/cli, @graphql-codegen/typescript-resolvers
### Describe the bug
Using both `enumValues` and the `typescript-resolvers` plugin causes the generated file to be categorically incompatible with TypeScript's `verbatimModuleSyntax` option.
Using `typescript-resolvers` adds the import `import { GraphQLResolveInfo } from 'graphql';`. This is fine, except that `GraphQLResolveInfo` is strictly just a type, and therefore requires the use of `import type` instead. Setting `useTypeImports: true` fixes this issue, but causes all the enums defined in `enumValues` to also be imported via `import type`, which then also breaks the build because they are not re-exported as types.
### Your Example Website or App
https://codesandbox.io/p/devbox/crazy-mestorf-gpqtvr?file=%2Fcodegen.ts%3A11%2C12-11%2C33
### Steps to Reproduce the Bug or Issue
1. Open the linked repro
2. Run `npm run typecheck`
3. It will fail with `'GraphQLResolveInfo' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.`
4. Enable `useTypeImports: true` and re-run `npm run typecheck`
5. It will fail with `'Foo' resolves to a type-only declaration and must be re-exported using a type-only re-export when 'verbatimModuleSyntax' is enabled.`
### Expected behavior
I expect to be able to make a types file that contains both resolvers and enums that compiles when using modern TS features.
Specifically, I would expect that the hard-coded type-only imports from `graphql` (namely `GraphQLResolveInfo` and `GraphQLScalarTypeConfig`, but there are likely more) would be imported using `import type` (or `import { type X }`) even without the use of `useTypeImports`, and/or that using `useTypeImports` would still import `enumValues` as values, not as types.
In general I would expect that `useTypeImports` wouldn't even be an option, I would expect that types would be imported as types and values imported as values without the end user needing to configure the import style.
### Screenshots or Videos
_No response_
### Platform
- OS: Any
- NodeJS: 20
- `graphql` version: `^16.2.0`
- `@graphql-codegen/*` version(s): `^4.0.1`
### Codegen Config File
_No response_
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.