Skip to content

Apollo v4 CodeGen Broken w/o config OverridesΒ #1216

@ksylvest

Description

@ksylvest

Which packages are impacted by your issue?

@graphql-codegen/typescript-react-apollo

Describe the bug

When using @graphql-codegen with the typescript-react-apollo plugin and @apollo/client v4 the generated code is invalid. Generated hooks (e.g. useQuery / useMutation) must be imported from @apollo/client/react, but are imported through @apollo/client. This causes a generated file to compile.

A workaround is to manually specify the following in the codegen.ts file:

config: {
  apolloReactCommonImportFrom: "@apollo/client/react",
  apolloReactHooksImportFrom: "@apollo/client/react",
}

Your Example Website or App

N/A

Steps to Reproduce the Bug or Issue

  1. Bump @apollo/client from v3 to v4
  2. Run codegen
  3. Build the generated code.

Expected behavior

The file does not compile and it is expected to compile.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: v24

Codegen Config File

No response

Additional context

No response

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