Skip to content

Commit

Permalink
Shallow-clone incoming.edges objects to ensure extensibility.
Browse files Browse the repository at this point in the history
Follow-up to #7103.
  • Loading branch information
benjamn committed Oct 1, 2020
1 parent ae2592b commit 6484a67
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/utilities/policies/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,14 @@ export function relayStylePagination<TNode = Reference>(
},

merge(existing = makeEmptyData(), incoming, { args, isReference, readField }) {
const incomingEdges = incoming.edges || [];
if (incomingEdges.length) {
incomingEdges.forEach(edge => {
if (isReference(edge)) {
// In case edge is a Reference, we read out its cursor field
// and store it as an extra property of the Reference object.
edge.cursor = readField<string>("cursor", edge);
}
});
}
const incomingEdges = incoming.edges ? incoming.edges.map(edge => {
if (isReference(edge = { ...edge })) {
// In case edge is a Reference, we read out its cursor field and
// store it as an extra property of the Reference object.
edge.cursor = readField<string>("cursor", edge);
}
return edge;
}) : [];

if (incoming.pageInfo) {
// In case we did not request the cursor field for edges in this
Expand Down

0 comments on commit 6484a67

Please sign in to comment.