Skip to content

Commit c670e3a

Browse files
shobhitsharmabenjamn
authored andcommitted
Handle falsy incoming data gracefully in offsetLimitPagination().merge (#9705)
1 parent 4571e1a commit c670e3a

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
- Provide `@apollo/client/**/*.cjs.native.js` versions of every `@apollo/client/**/*.cjs` bundle (including dependencies `ts-invariant` and `zen-observable-ts`) to help React Native's Metro bundler automatically resolve CommonJS entry point modules. **These changes should render unnecessary [the advice we gave in the v3.5.4 section below about `metro.config.js`](#apollo-client-354-2021-11-19).** <br/>
1717
[@benjamn](https://github.com/benjamn) in [#9716](https://github.com/apollographql/apollo-client/pull/9716)
1818

19+
- Handle falsy `incoming` data more gracefully in `offetLimitPagination().merge` function. <br/>
20+
[@shobhitsharma](https://github.com/shobhitsharma) in [#9705](https://github.com/apollographql/apollo-client/pull/9705)
21+
1922
## Apollo Client 3.6.3 (tagged as `next` on npm)
2023

2124
### Bug Fixes

src/utilities/policies/pagination.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,23 @@ export function offsetLimitPagination<T = Reference>(
3232
keyArgs,
3333
merge(existing, incoming, { args }) {
3434
const merged = existing ? existing.slice(0) : [];
35-
if (args) {
36-
// Assume an offset of 0 if args.offset omitted.
37-
const { offset = 0 } = args;
38-
for (let i = 0; i < incoming.length; ++i) {
39-
merged[offset + i] = incoming[i];
35+
36+
if (incoming) {
37+
if (args) {
38+
// Assume an offset of 0 if args.offset omitted.
39+
const { offset = 0 } = args;
40+
for (let i = 0; i < incoming.length; ++i) {
41+
merged[offset + i] = incoming[i];
42+
}
43+
} else {
44+
// It's unusual (probably a mistake) for a paginated field not
45+
// to receive any arguments, so you might prefer to throw an
46+
// exception here, instead of recovering by appending incoming
47+
// onto the existing array.
48+
merged.push.apply(merged, incoming);
4049
}
41-
} else {
42-
// It's unusual (probably a mistake) for a paginated field not
43-
// to receive any arguments, so you might prefer to throw an
44-
// exception here, instead of recovering by appending incoming
45-
// onto the existing array.
46-
merged.push.apply(merged, incoming);
4750
}
51+
4852
return merged;
4953
},
5054
};

0 commit comments

Comments
 (0)