Skip to content

typescript-rtk-query v4.0.1 generates TypedDocumentString incompatible with RTK Query #10759

@vldslv-a

Description

@vldslv-a

Which packages are impacted by your issue?

@graphql-codegen/typescript-rtk-query

Describe the bug

After updating @graphql-codegen/typescript-rtk-query from ^3.1.2 to ^4.0.1, the plugin hardcodes documentMode: DocumentMode.string in its visitor constructor. This generates documents wrapped in new TypedDocumentString(...) which is incompatible with RTK Query type expectations.

Type error:
Type 'TypedDocumentString' is not assignable to type 'string | DocumentNode'.

Your Example Website or App

Steps to Reproduce the Bug or Issue

  1. Use typescript-rtk-query plugin with near-operation-file preset
  2. Update @graphql-codegen/typescript-rtk-query to ^4.0.1
  3. Run codegen
  4. Run type checking
  5. See error: Type 'TypedDocumentString' is not assignable to type 'string | DocumentNode'

Expected behavior

The plugin should generate documents as plain gql strings (graphQLTag mode) or DocumentNode, compatible with RTK Query's type: { document: string | DocumentNode; ... }. The documentMode in codegen config should be respected instead of being hardcoded to DocumentMode.string.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • NodeJS: [e.g. 18.5.0]
  • graphql version: [e.g. 16.3.0]
  • @graphql-codegen/* version(s): [e.g. 2.6.2]

Codegen Config File

generates:
src/:
preset: near-operation-file
plugins:
- typescript-operations
- typescript-rtk-query:
importBaseApiFrom: '@my/graphql-client'
exportHooks: true
config:
documentMode: graphQLTag # ignored by typescript-rtk-query v4

Additional context

In v4.0.1, RTKQueryVisitor constructor hardcodes:
documentMode: visitor_plugin_common_1.DocumentMode.string

This cannot be overridden via config. Workaround: downgrade to ^3.1.2.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions