import { ApolloLink } from "@apollo/client/link/core";
import { OperationBatcher } from "./batching.js";
export { OperationBatcher } from "./batching.js";
export class BatchLink extends ApolloLink {
    batcher;
    constructor(fetchParams) {
        super();
        const { batchDebounce, batchInterval = 10, batchMax = 0, batchHandler = () => null, batchKey = () => "", } = fetchParams || {};
        this.batcher = new OperationBatcher({
            batchDebounce,
            batchInterval,
            batchMax,
            batchHandler,
            batchKey,
        });
        //make this link terminating
        if (fetchParams.batchHandler.length <= 1) {
            this.request = (operation) => this.batcher.enqueueRequest({ operation });
        }
    }
    request(operation, forward) {
        return this.batcher.enqueueRequest({
            operation,
            forward,
        });
    }
}
//# sourceMappingURL=batchLink.js.map
