···11+---
22+'@urql/core': minor
33+---
44+55+Deprecate the `dedupExchange`. The functionality of deduplicating queries and subscriptions has now been moved into and absorbed by the `Client`.
66+77+Previously, the `Client` already started doing some work to share results between
88+queries, and to avoid dispatching operations as needed. It now only dispatches operations
99+strictly when the `dedupExchange` would allow so as well, moving its logic into the
1010+`Client`.
···11-import { filter, pipe, tap } from 'wonka';
21import { Exchange } from '../types';
3243/** Default deduplication exchange.
55- *
66- * @remarks
77- * The `dedupExchange` deduplicates queries and subscriptions that are
88- * started with identical documents and variables by deduplicating by
99- * their {@link Operation.key}.
1010- * This can prevent duplicate requests from being sent to your GraphQL API.
1111- *
1212- * Because this is a very safe exchange to add to any GraphQL setup, it’s
1313- * not only the default, but we also recommend you to always keep this
1414- * exchange added and included in your setup.
1515- *
1616- * Hint: In React and Vue, some common usage patterns can trigger duplicate
1717- * operations. For instance, in React a single render will actually
1818- * trigger two phases that execute an {@link Operation}.
44+ * @deprecated
55+ * This exchange's functionality is now built into the {@link Client}.
196 */
2020-export const dedupExchange: Exchange = ({ forward, dispatchDebug }) => {
2121- const inFlightKeys = new Set<number>();
2222- return ops$ =>
2323- pipe(
2424- forward(
2525- pipe(
2626- ops$,
2727- filter(operation => {
2828- if (
2929- operation.kind === 'teardown' ||
3030- operation.kind === 'mutation'
3131- ) {
3232- inFlightKeys.delete(operation.key);
3333- return true;
3434- }
3535-3636- const isInFlight = inFlightKeys.has(operation.key);
3737- inFlightKeys.add(operation.key);
3838-3939- if (isInFlight) {
4040- dispatchDebug({
4141- type: 'dedup',
4242- message: 'An operation has been deduped.',
4343- operation,
4444- });
4545- }
4646-4747- return !isInFlight;
4848- })
4949- )
5050- ),
5151- tap(result => {
5252- if (!result.hasNext) {
5353- inFlightKeys.delete(result.operation.key);
5454- }
5555- })
5656- );
5757-};
77+export const dedupExchange: Exchange = ({ forward }) => ops$ => forward(ops$);