Skip to content

Cannot find name 'TypedDocumentString' with typescript-rtk-query plugin #1410

@cheungpat

Description

@cheungpat

Which packages are impacted by your issue?

@graphql-codegen/typescript-rtk-query

Describe the bug

Since @graphql-codegen/typescript-rtk-query 4.0.0, the generated typescript file contains references to TypedDocumentString, but this class is not defined in the same file. This causes TypeScript to print out this error when building:

Cannot find name 'TypedDocumentString'.

Your Example Website or App

https://codesandbox.io/p/devbox/solitary-sea-pg72wt

Steps to Reproduce the Bug or Issue

  1. Follow instructions in https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-rtk-query to add rtk-query plugin to codegen.ts
  2. Run codegen
  3. The generated types.ts contains references to TypedDocumentString, which is not defined.

Expected behavior

I expect the generated types.ts to have no TypeScript errors when building (i.e. without using TypedDocumentString or having its definition included in the file).

Screenshots or Videos

Image

Platform

  • OS: Linux
  • NodeJS: 20.12.1
  • graphql version: 16.6.0
  • @graphql-codegen/typescript version: 4.0.1
  • @graphql-codegen/typescript-rtk-query version: 4.0.0

Codegen Config File

import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "schema.graphql",
  documents: "document.graphql",
  generates: {
    "types.ts": {
      plugins: [
        "typescript",
        "typescript-operations",
        {
          "typescript-rtk-query": {
            importBaseApiFrom: "./baseApi",
            exportHooks: true,
          },
        },
      ],
    },
  },
};

export default config;

Additional context

  • The same codegen configuration was working prior to @graphql-codegen/typescript-rtk-query 4.0.0
  • I understand that client should use Client preset, but rtk-query is not listed as one of the supported clients on the webpage.
  • The reason for upgrade is because typescript-rtk-query implicitly depends on immutable which has a vulnerability prior to version 3.8.3.

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