[typescript-react-query] Does not use own types when combined with import-types and typescript-operations
See original GitHub issueDescribe the bug
I would like to separate out my schema-types from operation-types+hooks, and I believe I’ve found the config which should accomplish it. However, when using import-types-preset, all of the types are referenced from the Types import, even if they’re being exported from the same file.
To Reproduce Steps to reproduce the behavior:
https://codesandbox.io/s/graphql-code-generator-6909-lu5rm?file=/hooks.ts
Note typescript errors for Types.UserQuery, since UserQuery is defined in the same file, not ./types.
- My GraphQL schema:
See reproduction
- My GraphQL operations:
See reproduction
- My
codegen.ymlconfig file:
generates:
./types.ts:
plugins:
- typescript
./hooks.ts:
preset: import-types
presetConfig:
typesPath: ./types
plugins:
- typescript-operations
- typescript-react-query
Expected behavior
I expect that types being exported from hooks.ts are not attempted to be imported from types.ts.
Environment:
- OS: mac
@graphql-codegen/...: latest, see reproduction- NodeJS: 16
Additional context A similar issue which was recently fixed: https://github.com/dotansimha/graphql-code-generator/issues/6520
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:10 (1 by maintainers)

Top Related StackOverflow Question
Sure, I added this file:
fix-types.js
Then I run a hook in my codegen.yml file
Then I added a
graphql:codegen:fixscript in mypackage.jsonthat runsfix-types.jsIf anyone’s interested, I have temporarily solved my issue in a hacky way. I run an automated post-codegen script that replaces
Types.XwithXifX’s type is present in the file.