Skip to content

Commit

Permalink
fix: relay style pagination not supporting non-root args #8524
Browse files Browse the repository at this point in the history
  • Loading branch information
zanechua committed Apr 8, 2023
1 parent 895bcdc commit cb28c87
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utilities/policies/pagination.ts
Expand Up @@ -191,17 +191,19 @@ export function relayStylePagination<TNode extends Reference = Reference>(
let prefix = existing.edges;
let suffix: typeof prefix = [];

if (args && args.after) {
if (args && args.after || args && args.input && args.input.after) {
// This comparison does not need to use readField("cursor", edge),
// because we stored the cursor field of any Reference edges as an
// extra property of the Reference object.
const index = prefix.findIndex(edge => edge.cursor === args.after);
const after = args.after || args.input.after;
const index = prefix.findIndex(edge => edge.cursor === after);
if (index >= 0) {
prefix = prefix.slice(0, index + 1);
// suffix = []; // already true
}
} else if (args && args.before) {
const index = prefix.findIndex(edge => edge.cursor === args.before);
} else if (args && args.before || args && args.input && args.input.before) {
const before = args.before || args.input.before;
const index = prefix.findIndex(edge => edge.cursor === before);
suffix = index < 0 ? prefix : prefix.slice(index);
prefix = [];
} else if (incoming.edges) {
Expand Down

0 comments on commit cb28c87

Please sign in to comment.