Open myronmarston opened 5 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Could someone from the Relay team confirm whether this is an accurate interpretation or a misunderstanding, and whether it’s a bug or intended behavior? I’m implementing a GraphQL backend and unsure how to proceed. There's already a PR to fix this issue (#4365), but it would be great to have confirmation from the Relay team.
It appears that the formal algorithm for
hasPreviousPage
andhasNextPage
, as defined in the Relay Connections Cursor Spec, has a couple bugs. That is, if I implement my server to follow the spec exactly as written, there are some situations wherefalse
will be returned forhasPreviousPage
when there in fact is a previous page, andfalse
will be returned forhasNextPage
when there is in fact a next page.Here is the current spec I am working off of:
For the bugs listed below, assume we're working with a list of edges like
[a, b, c, d, e]
(where the letters are the cursors for each edge).Bug # 1
If my server is called with just
after: a
(nofirst
,last
orbefore
arguments), then[b, c, d, e]
will be returned as the page of edges. The algorithm requires thatfalse
be returned forhasPreviousPage
, even though there is the previous page of[a]
. Specifically,last
is not set butafter
is, so this part of the algorithm applies:We can efficiently determine that no elements exist prior to the
after
cursor value ofa
(it is the first edge, after all) so we fall through to theReturn {false}
bit and returnfalse
.In general, it seems like there's a mismatch between the algorithm for
ApplyCursorsToEdges
removing elements on or beforeafter
whilehasPreviousPage
only considers if any elements come beforeafter
(rather than also considering the element identified byafter
itself).The same bug also exists for
hasNextPage
; if my server is called with justbefore: e
, the spec tells me I have to returnfalse
forhasNextPage
even though a next page of[e]
does in fact exist.Bug # 2
If my server is called with
last: 3, after: a, before: e
, then[b, c, d]
will be returned as the page of edges, but the algorithm requires thatfalse
be returned forhasPreviousPage
, even though there is a previous page ([a]
). Sincelast
is set, this part of the algorithm applies:Calling
ApplyCursorsToEdges(allEdges, before, after)
whenallEdges = [a, b, c, d, e] and before = e and after = a
results in[b, c, d]
.edges
contains 3 elements, which is the value oflast
; therefore, according toIf {edges} contains more than {last} elements return {true}, otherwise {false}
we must returnfalse
.The same bug also exists for
hasNextPage
; if my server is called with justfirst: 3, after: a, before: 3
, the spec tells me I have to returnfalse
forhasNextPage
even though a next page of[e]
does in fact exist.