dotansimha / dotansimha/graphql-code-generator-community
[typescript-rtk-query] TypedDocumentString cast 'as unknown as string' causes runtime issues
- 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
In `packages/plugins/typescript/rtk-query/src/visitor.ts` in https://github.com/dotansimha/graphql-code-generator-community/commit/bebe34b2d141161d77348e85dbd223f04cba96e8 when the `TypedDocumentString` was introduced, the visitor was updated to output `document: ${documentVariableName} as unknown as string` - but at runtime `documentVariableName` is actually of type `TypedDocumentString`. This causes runtime issues as consuming code is expecting an actual string.
Proposed bugfix in https://github.com/jamesgecargo/graphql-code-generator-community/commit/5d02bf3ff30ffe13c7d0e8d3b182143cae8b50ac
### Your Example Website or App
https://github.com/jamesgecargo/graphql-code-generator-community/commit/5d02bf3ff30ffe13c7d0e8d3b182143cae8b50ac
### Steps to Reproduce the Bug or Issue
1. Regenerate any query
2. See the cast `as unknown as string`
3. Get runtime exception because a `TypedDocumentString` is getting passed around instead of an actual string
### Expected behavior
No runtime exceptions because the query should be a string, not a `TypedDocumentString`.
### 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 and inspect the generated document expression, then compare it with the proposed fix commit. Regenerate a query and verify that the emitted document is an actual string and no runtime exception occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100