Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollo/utils.fetcher

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/utils.fetcher

Minimal web-style fetch TypeScript typings

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
730K
decreased by-35.67%
Maintainers
4
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 08 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc