From cb28c87337166d86074f00acfdb8a3f29939b9d2 Mon Sep 17 00:00:00 2001 From: Zane Chua <4265429+zanechua@users.noreply.github.com> Date: Sun, 9 Apr 2023 04:14:20 +0800 Subject: [PATCH] fix: relay style pagination not supporting non-root args #8524 --- src/utilities/policies/pagination.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/utilities/policies/pagination.ts b/src/utilities/policies/pagination.ts index 163b1631601..770517ddca5 100644 --- a/src/utilities/policies/pagination.ts +++ b/src/utilities/policies/pagination.ts @@ -191,17 +191,19 @@ export function relayStylePagination( 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) {