Type alias Exchange

Exchange: ((input) => ExchangeIO)

Type declaration

    • (input): ExchangeIO
    • 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.

      See

      Example

      import { pipe, onPush } from 'wonka';
      import { Exchange } from '@urql/core';

      const debugExchange: Exchange => {
      return ops$ => pipe(
      ops$,
      onPush(operation => console.log(operation)),
      forward,
      onPush(result => console.log(result)),
      );
      };

      Parameters

      Returns ExchangeIO

Generated using TypeDoc