@apollo/client-codemod-migrate-3-to-4

中文文档
1.0.2发布于 2025/08/28MITES Module构建来源已验证近 30 天下载 2361

Apollo Client Codemod to migrate from version 3 to version 4

原始使用文档
文档目录4 节
  1. Using this codemod
  2. Available codemods:
  3. Usage against TypeScript/TSX
  4. Using the Codemod from a specific PR

Using this codemod

You can run this codemod with the following command:

npx @apollo/client-codemod-migrate-3-to-4 --parser ts file1.ts file2.ts

if you want to only run a specific codemod:

npx @apollo/client-codemod-migrate-3-to-4 --parser ts file1.ts file2.ts  --codemod imports

Available codemods:

In the order they will be applied per default if you don't manually specify a codemod:

  • legacyEntryPoints: Moves imports from old legacy entry points like @apollo/client/main.cjs or @apollo/client/react/react.cjs to the new entry points like @apollo/client or @apollo/client/react.
  • imports: Moves imports that have been moved or renamed in Apollo Client 4. Also moves types into namespace imports where applicable.
  • links: Moves split, from, concat and empty onto the ApolloLink namespace, changes funtion link invocations like createHttpLink(...) to their class equivalents like (new HttpLink(...)). Does not change setContext((operation, prevContext) => {}) to new ContextLink((prevContext, operation) => {}) - this requires manual intervention, as the order of callback arguments is flipped and this is not reliable codemoddable.
  • removals: Points all imports of values or types that have been removed in Apollo Client 4 to the @apollo/client/v4-migration entry point. That entry point contains context for each removal, oftentimes with migration instructions.
  • clientSetup: Applies the following steps from the migration guide to your Apollo Client setup code
    • Moves uri, headers and credentials to the link option and creates a new HttpLink instance
    • Moves name and version into a clientAwareness option
    • Adds a localState option with a new LocalState instance, moves resolvers, and removes typeDefs and fragmentMatcher options
    • Changes the connectToDevTools option to devtools.enabled
    • Renames disableNetworkFetches to prioritizeCacheValues
    • If dataMasking is enabled, adds a template for global type augmentation to re-enable data masking types
    • Adds the incrementalHandler option and adds a template for global type augmentation to accordingly type network responses in custom links
    • Removes the TCacheShape type argument from all ApolloClient usages (types and constructor calls)

Usage against TypeScript/TSX

There is some syntax overlap between TypeScript and TypeScript-JSX files, so you might need to run the Codemod against both file extensions sepearately to avoid errors:

npx @apollo/client-codemod-migrate-3-to-4 --parser ts --ignore-pattern="*.{tsx,d.ts}" file1.ts file2.ts
npx @apollo/client-codemod-migrate-3-to-4 --parser tsx --ignore-pattern="*.ts" file1.ts file2.ts

Using the Codemod from a specific PR

npx https://pkg.pr.new/apollographql/apollo-client/@apollo/client-codemod-migrate-3-to-4@12733 --parser ts file1.ts file2.ts

版本与发布记录

@apollo/client-codemod-migrate-3-to-4 共发布 7 个版本,首次发布于 2025/06/28;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.2latest2025/08/281.2 年前
1.0.12025/08/261.2 年前
1.0.02025/08/221.2 年前
1.0.0-rc.3nextrc2025/08/211.2 年前
1.0.0-rc.22025/08/151.2 年前
1.0.0-rc.12025/07/191.3 年前

关于 @apollo/client-codemod-migrate-3-to-4 的常见问题

@apollo/client-codemod-migrate-3-to-4 是什么?

Apollo Client Codemod to migrate from version 3 to version 4

如何安装 @apollo/client-codemod-migrate-3-to-4?

在项目目录运行 npm install @apollo/client-codemod-migrate-3-to-4,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 apollo-client-codemod-migrate-3-to-4,可以用 npx apollo-client-codemod-migrate-3-to-4 直接运行。

@apollo/client-codemod-migrate-3-to-4 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/apollo__client-codemod-migrate-3-to-4 是否存在。

@apollo/client-codemod-migrate-3-to-4 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@apollo/client-codemod-migrate-3-to-4 可以商用吗?

@apollo/client-codemod-migrate-3-to-4 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@apollo/client-codemod-migrate-3-to-4 的下载量有多少?

根据 npm 官方下载统计,@apollo/client-codemod-migrate-3-to-4 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,361 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@apollo/client-codemod-migrate-3-to-4 还在维护吗?

最新版本 1.0.2 发布于 2025/08/28(1.2 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/06/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。