feat: add fetchOptions
parameter to control fetch()
#291
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Description
This PR adds a new
fetchOptions
parameter tocreateClient()
and all client methods that make network requests.The parameter allows for customizing how
fetch()
is called.Supported options
The TypeScript types support a subset of the global
RequestInit
type:headers
(only plain objects are supported)cache
signal
These three parameters have known real-world use cases, while others, like
credentials
, currently do not.If we learn that other parameters are needed, we can add support for them in the future.
Adding support for project-specific options
@prismicio/client
's type forfetchOptions
can be augmented on a per-project basis using module augmentation.This is useful if a project needs to add support for a
RequestInit
property that is not supported by default. It is also useful if projects have project-specificRequestInit
features that need to be added, like Next.js'next
parameter.Deprecating
signal
parameter in favor offetchOptions.signal
The
signal
parameter has been replaced by the more aptfetchOptions.signal
.signal
will continue to be supported, but has been marked as deprecated. Please migrate tofetchOptions.signal
.Checklist:
🐈⬛