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

fix: relay style pagination not supporting non-root args #8524 #10746

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions src/utilities/policies/pagination.ts
Original file line number Diff line number Diff line change
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