UNPKG

@graphprotocol/client-auto-pagination

Version:

`graph-client` implements automatic pagination using `first:` and `after:` filters of `graph-node`.

23 lines (22 loc) 975 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useAutoPagination = void 0; const utils_1 = require("@graphql-tools/utils"); const shared_js_1 = require("./shared.js"); function useAutoPagination(options = shared_js_1.DEFAULT_OPTIONS) { return { onSubgraphExecute({ executionRequest, setExecutionRequest }) { setExecutionRequest((0, shared_js_1.transformExecutionRequest)(executionRequest, options)); return ({ result, setResult }) => { if ((0, utils_1.isAsyncIterable)(result)) { const iterator = result[Symbol.asyncIterator](); setResult((0, utils_1.mapAsyncIterator)(iterator, shared_js_1.transformExecutionResponse)); } else { setResult((0, shared_js_1.transformExecutionResponse)(result)); } }; } }; } exports.useAutoPagination = useAutoPagination;