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.
Exchange
s are both extensions for aClient
and part of the control-flow executingOperation
s.Remarks
Exchange
s are responsible for the pipeline inurql
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 ofOperation
s and returns a stream ofOperationResult
s.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