Skip to content

Commit

Permalink
Default args.offset to 0 in offsetLimitPagination. (#7141)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn authored Oct 10, 2020
1 parent 93d65e9 commit 8e92be3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Apollo Client 3.2.3

## Improvements

- Default `args.offset` to zero in `offsetLimitPagination`. <br/>
[@benjamn](https://github.com/benjamn) in [#7141](https://github.com/apollographql/apollo-client/pull/7141)

## Apollo Client 3.2.2

## Bug Fixes
Expand Down
16 changes: 12 additions & 4 deletions src/utilities/policies/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ export function offsetLimitPagination<T = Reference>(
keyArgs,
merge(existing, incoming, { args }) {
const merged = existing ? existing.slice(0) : [];
const start = args ? args.offset : merged.length;
const end = start + incoming.length;
for (let i = start; i < end; ++i) {
merged[i] = incoming[i - start];
if (args) {
// Assume an offset of 0 if args.offset omitted.
const { offset = 0 } = args;
for (let i = 0; i < incoming.length; ++i) {
merged[offset + i] = incoming[i];
}
} else {
// It's unusual (probably a mistake) for a paginated field not
// to receive any arguments, so you might prefer to throw an
// exception here, instead of recovering by appending incoming
// onto the existing array.
merged.push.apply(merged, incoming);
}
return merged;
},
Expand Down

0 comments on commit 8e92be3

Please sign in to comment.