@apollo/utils.fetcher

中文文档
3.1.0发布于 2023/11/09MITTypeScript零依赖近 30 天下载 1358.4万

Minimal web-style fetch TypeScript typings

原始使用文档

Fetcher interface

This package defines TypeScript typings for a subset of the web fetch API.

The goal is for software that wants to be able to make HTTP requests in a configurable fashion to be able to declare an option of this type; users can pass in any valid fetch implementation such as node-fetch, make-fetch-happen, or undici.

The actual fetch API is very flexible. You can specify requests either as JSON-style objects or as objects of the Request and Headers classes. However, some fetch implementations distinguish between these cases by using (for example) instanceof Headers, where Headers is the particular class defined by that implementation. So if you want to write portable code that should work with any fetch implementation, you need to use JSON-style objects rather than a particular implementation's classes. (For example, a Headers object created with node-fetch v2 will not be properly recognized by make-fetch-happen v10.)

Additionally, some fetch implementations accept various types for their request body; for example, node-fetch supports the use of FormData objects specifically from the form-data package. You may choose to use different types for your request body, so long as those types are supported by the fetch implementation of your choice. You will likely need to use a type assertion to convince TypeScript that your body is valid. Unfortunately, because different fetch implementations access different FormData classes, we weren't excited about the outcome of this relevant PR and decided to undo it, but might be open to a simpler approach that solves the problem without the need for type assertions.

Specifically, the Fetcher interface only declares options that are currently required by the software that uses it, such as Apollo Server and Apollo Gateway. If more options are required (and they are implemented with the same types in all fetch implementations), we can add them as needed.

This package is validated to be compatible with the typings of node-fetch v2, make-fetch-happen v10, and undici v5.

版本与发布记录

@apollo/utils.fetcher 共发布 7 个版本,首次发布于 2022/04/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.1.0latest2023/11/092 年前
3.0.02023/04/183 年前
2.0.12023/04/043 年前
2.0.02022/11/193 年前
1.1.12022/10/184 年前
1.1.02022/08/114 年前

关于 @apollo/utils.fetcher 的常见问题

@apollo/utils.fetcher 是什么?

Minimal web-style fetch TypeScript typings

如何安装 @apollo/utils.fetcher?

在项目目录运行 npm install @apollo/utils.fetcher,或使用 pnpm add / yarn add / bun add。

@apollo/utils.fetcher 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@apollo/utils.fetcher 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@apollo/utils.fetcher 可以商用吗?

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

@apollo/utils.fetcher 的下载量有多少?

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

@apollo/utils.fetcher 还在维护吗?

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