Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@urql/exchange-persisted-fetch
Advanced tools
Readme
The persistedFetchExchange
is an exchange that builds on the regular fetchExchange
but adds support for Persisted Queries.
First install @urql/exchange-persisted-fetch
alongside urql
:
yarn add @urql/exchange-persisted-fetch
# or
npm install --save @urql/exchange-persisted-fetch
You'll then need to add the persistedFetchExchange
method, that this package exposes,
to your exchanges
.
import { createClient, dedupExchange, fetchExchange, cacheExchange } from 'urql';
import { persistedFetchExchange } from '@urql/exchange-persisted-fetch';
const client = createClient({
url: 'http://localhost:1234/graphql',
exchanges: [
dedupExchange,
cacheExchange,
persistedFetchExchange({
/* optional config */
}),
fetchExchange,
],
});
The persistedQueryExchange
supports three configuration options:
preferGetForPersistedQueries
: Use GET
for fetches with persisted queriesenforcePersistedQueries
: This disables automatic persisted queries and disables any retry
logic for how the API responds to persisted queries. Instead it's assumed that they'll always
succeed.generateHash
: A function that takes a GraphQL query and returns the hashed result. This defaults to the window.crypto
API in the browser and the crypto
module in node.The persistedFetchExchange
only handles queries, so for mutations we keep the
fetchExchange
around alongside of it.
If you want to generate hashes at build-time you can use a webpack-loader to achieve this, when using this all you need to do in this exchange is the following:
import { createClient, dedupExchange, fetchExchange, cacheExchange } from 'urql';
import { persistedFetchExchange } from '@urql/exchange-persisted-fetch';
const client = createClient({
url: 'http://localhost:1234/graphql',
exchanges: [
dedupExchange,
cacheExchange,
persistedFetchExchange({
generateHash: (_, document) => document.documentId,
}),
fetchExchange,
],
});
FAQs
An exchange that allows for persisted queries support when fetching queries
The npm package @urql/exchange-persisted-fetch receives a total of 2,034 weekly downloads. As such, @urql/exchange-persisted-fetch popularity was classified as popular.
We found that @urql/exchange-persisted-fetch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 24 open source maintainers collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.