dotansimha / dotansimha/graphql-code-generator-community
[typescript-rtk-query] Void type not valid when query has no arguments
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### Which packages are impacted by your issue?
@graphql-codegen/typescript-rtk-query
### Describe the bug
At https://github.com/dotansimha/graphql-code-generator-community/blob/bb54d0071aa75e6918b32b832b0850997d9a270f/packages/plugins/typescript/rtk-query/src/visitor.ts#L134 falling back to `void` upsets the consuming code and so causes typescript build errors: `Type 'void' is not assignable to type 'object | undefined'.`
Instead if we fall back to `undefined` then the typescript build errors go away.
Sample fix provided in https://github.com/jamesgecargo/graphql-code-generator-community/commit/dea6215af1070c965095be3fe287e91bc664c221
### Your Example Website or App
https://github.com/jamesgecargo/graphql-code-generator-community/commit/dea6215af1070c965095be3fe287e91bc664c221
### Steps to Reproduce the Bug or Issue
1. Regenerate a query without any variables
2. See the red squiggly error from typescript `Type 'void' is not assignable to type 'object | undefined'.`
### Expected behavior
No typescript error
### Screenshots or Videos
_No response_
### Platform
- OS: Windows 11
- NodeJS: 24.11.0
- "graphql": "^16.13.2",
"graphql-request": "^6.1.0",
"@graphql-codegen/cli": "^7.2.0",
"@graphql-codegen/near-operation-file-preset": "^5.2.1",
"@graphql-codegen/typescript": "^6.1.0",
"@graphql-codegen/typescript-operations": "^6.1.0",
"@graphql-codegen/typescript-rtk-query": "^4.0.4",
### Codegen Config File
_No response_
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in packages/plugins/typescript/rtk-query/src/visitor.ts at the fallback around line 134, then regenerate a query without variables to reproduce the TypeScript error. Done means the generated query uses a type accepted by the consumer and the “Type 'void' is not assignable to type 'object | undefined'” error no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100