-
-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Deprecate the dedupExchange and absorb hasNext checks int…
…o Client (#3058)
- Loading branch information
Showing
5 changed files
with
50 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@urql/core': minor | ||
--- | ||
|
||
Deprecate the `dedupExchange`. The functionality of deduplicating queries and subscriptions has now been moved into and absorbed by the `Client`. | ||
|
||
Previously, the `Client` already started doing some work to share results between | ||
queries, and to avoid dispatching operations as needed. It now only dispatches operations | ||
strictly when the `dedupExchange` would allow so as well, moving its logic into the | ||
`Client`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,7 @@ | ||
import { filter, pipe, tap } from 'wonka'; | ||
import { Exchange } from '../types'; | ||
|
||
/** Default deduplication exchange. | ||
* | ||
* @remarks | ||
* The `dedupExchange` deduplicates queries and subscriptions that are | ||
* started with identical documents and variables by deduplicating by | ||
* their {@link Operation.key}. | ||
* This can prevent duplicate requests from being sent to your GraphQL API. | ||
* | ||
* Because this is a very safe exchange to add to any GraphQL setup, it’s | ||
* not only the default, but we also recommend you to always keep this | ||
* exchange added and included in your setup. | ||
* | ||
* Hint: In React and Vue, some common usage patterns can trigger duplicate | ||
* operations. For instance, in React a single render will actually | ||
* trigger two phases that execute an {@link Operation}. | ||
* @deprecated | ||
* This exchange's functionality is now built into the {@link Client}. | ||
*/ | ||
export const dedupExchange: Exchange = ({ forward, dispatchDebug }) => { | ||
const inFlightKeys = new Set<number>(); | ||
return ops$ => | ||
pipe( | ||
forward( | ||
pipe( | ||
ops$, | ||
filter(operation => { | ||
if ( | ||
operation.kind === 'teardown' || | ||
operation.kind === 'mutation' | ||
) { | ||
inFlightKeys.delete(operation.key); | ||
return true; | ||
} | ||
|
||
const isInFlight = inFlightKeys.has(operation.key); | ||
inFlightKeys.add(operation.key); | ||
|
||
if (isInFlight) { | ||
dispatchDebug({ | ||
type: 'dedup', | ||
message: 'An operation has been deduped.', | ||
operation, | ||
}); | ||
} | ||
|
||
return !isInFlight; | ||
}) | ||
) | ||
), | ||
tap(result => { | ||
if (!result.hasNext) { | ||
inFlightKeys.delete(result.operation.key); | ||
} | ||
}) | ||
); | ||
}; | ||
export const dedupExchange: Exchange = ({ forward }) => ops$ => forward(ops$); |