Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default args.offset to 0 in offsetLimitPagination. #7141

Merged
merged 2 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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