import { ApolloLink , Operation , FetchResult , Observable , NextLink , } from 'apollo-link' ; import { OperationBatcher , BatchHandler } from './batching' ; export { OperationBatcher , BatchableRequest , BatchHandler } from './batching' ; export namespace BatchLink { export interface Options { /**
         * The interval at which to batch, in milliseconds.
         *
         * Defaults to 10.
         */ batchInterval ? : number ; /**
         * The maximum number of operations to include in one fetch.
         *
         * Defaults to 0 (infinite operations within the interval).
         */ batchMax ? : number ; /**
         * The handler that should execute a batch of operations.
         */ batchHandler ? : BatchHandler ; /**
         * creates the key for a batch
         */ batchKey ? : ( operation : Operation ) => string ; } } export class BatchLink extends ApolloLink { private batcher : OperationBatcher ; constructor ( fetchParams ? ) { super ( ) ; const { batchInterval = 10 , batchMax = 0 , batchHandler = ( ) => null , batchKey = ( ) => '' , } = fetchParams || { } ; this . batcher = new OperationBatcher ( { batchInterval , batchMax , batchHandler , batchKey , } ) ; if ( fetchParams . batchHandler . length <= 1 ) { this . request = operation => this . batcher . enqueueRequest ( { operation } ) ; } } public request ( operation , forward ? ) { return this . batcher . enqueueRequest ( { operation , forward , } ) ; } }