I’m using Apollo Client v4 (4.0.5) with Next.js App Router and GraphQL Code Generator (typescript-react-apollo) to generate TypeScript types and hooks for my GraphQL API.
Everything was working fine until I recently added some queries/mutations on the backend and regenerated my GraphQL types. Now, the generated code fails to compile with the following error:
Export skipToken doesn't exist in target module
1 | import { gql } from '@apollo/client';
> 2 | import * as Apollo from '@apollo/client';
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | export type Maybe<T> = T | null;
4 | export type InputMaybe<T> = Maybe<T>;
The export skipToken was not found in module .../@apollo/client/core/index.js [app-client] (ecmascript).
If I manually edit the file after generation to destructure skipToken like this, it works fine:
import * as Apollo from '@apollo/client/react';
const { skipToken } = Apollo;
here is my codegen config:
overwrite: true
schema: 'http://localhost:5000/graphql'
documents: 'src/graphql/**/*.graphql'
generates:
src/graphql/generated/graphql.ts:
plugins:
- 'typescript'
- 'typescript-operations'
- 'typescript-react-apollo'
config:
withHooks: true
withComponent: false
withHOC: false
skipTypename: false
# Tried disabling but didn't help:
# withSkipToken: false
# reactApolloVersion: 3
So why does GraphQL Codegen generate a broken skipToken import when using Apollo v4 in Next.js App Router and how can I configure typescript-react-apollo so it does not generate skipToken imports at all (or generates them in a working way)?
skipTokenis now exported from@apollo/client/react. The codegen and plugins may or may not have been updated yet -- what versions are you using? See also the warnings at the-guild.dev/graphql/codegen/plugins/typescript/…skipTokenlike this, it works fine", but now you are saying it "didn't change a thing" -- which one is it?