Exchanges are both extensions for a Client and part of the control-flow executing Operations.
Remarks
Exchanges are responsible for the pipeline in urql that accepts Operations and
returns OperationResults. They take care of adding functionality to a Client,
like deduplication, caching, and fetching (i.e. making GraphQL requests).
When passed to the Client, they're instantiated with the ExchangeInput object and return an ExchangeIO
function, which is a mapping function that receives a stream of Operations and returns a stream of OperationResults.
Like middleware, exchanges are composed, calling each other in a pipeline-like fashion, which is facilitated by exchanges
calling forward, which is set to the next exchange's ExchangeIO function in the pipeline.
Exchanges are both extensions for aClientand part of the control-flow executingOperations.Remarks
Exchanges are responsible for the pipeline inurqlthat accepts Operations and returns OperationResults. They take care of adding functionality to a Client, like deduplication, caching, and fetching (i.e. making GraphQL requests).When passed to the
Client, they're instantiated with the ExchangeInput object and return an ExchangeIO function, which is a mapping function that receives a stream ofOperations and returns a stream ofOperationResults.Like middleware, exchanges are composed, calling each other in a pipeline-like fashion, which is facilitated by exchanges calling forward, which is set to the next exchange's ExchangeIO function in the pipeline.
See
Example