Try to infinite scroll pagination

@Gabriel_Eliade I’ve experienced same issue here.
I found that method is really simple so I modified a bit and it works well now. Here’s my code.
I named it as startLimitPagination

import {
  FieldPolicy,
  Reference,
} from '@apollo/client';

type KeyArgs = FieldPolicy<any>['keyArgs'];
// A basic field policy that uses options.args.{offset,limit} to splice
// the incoming data into the existing array. If your arguments are called
// something different (like args.{start,count}), feel free to copy/paste
// this implementation and make the appropriate changes.
export function startLimitPagination<T = Reference>(
  keyArgs: KeyArgs = false,
): FieldPolicy<T[]> {
  return {
    keyArgs,
    merge(existing, incoming, {args}) {
      const merged = existing ? existing.slice(0) : [];
      const start = args ? args.start : merged.length;
      const end = start + incoming.length;
      for (let i = start; i < end; ++i) {
        merged[i] = incoming[i - start];
      }
      return merged;
    },
  };
}
1 Like