Apollo 3 pagination not merging

Viewed 336

so I'm suing react with apollo client. I have infinite-scroll components, which works:

<Paginate
            hasNextPage={meta?.hasNextPage ?? false}
            loading={paginateLoading}
            onLoadMore={() => {
                setPaginateLoading(true);
                fetchMore({
                    variables: {
                        pagination: {
                            limit: 20,
                            page: meta?.nextPage,
                        },
                    }}).then(() => setPaginateLoading(false));

And I had there updateQuery function, which I want to get rid of. So I have:

const cache = new InMemoryCache({
typePolicies: {
    Query: {
        fields: {
            myField: {
                merge(existing, incoming, { mergeObjects }) {
                    return mergeObjects(existing, incoming);
                },
            },

And Its fetching and fetching, but no data are updated. Some cases:

myField: relayStylePagination(),

Result: data is changing after every fetch (OK!) But not merged (what I want).

myField: concatPagination()

Result:

    ×
Unhandled Rejection (RangeError): Invalid array length
__spreadArrays
node_modules/tslib/tslib.es6.js:152
merge
/src/utilities/policies/pagination.ts:15
  12 | export function offsetLimitPagination(keyArgs) {
  13 |     if (keyArgs === void 0) { keyArgs = false; }
  14 |     return {
> 15 |         keyArgs: keyArgs,
  16 |         merge: function (existing, incoming, _a) {
  17 |             var args = _a.args;
  18 |             var merged = existing ? existing.slice(0) : [];

Any ideas?

0 Answers
Related