Skip to content

Commit

Permalink
Default args.offset to 0 in offsetLimitPagination.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Oct 9, 2020
1 parent b3e4b5a commit 68e8b87
Showing 1 changed file with 12 additions and 4 deletions.
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 68e8b87

Please sign in to comment.