apollo-cursor-pagination icon indicating copy to clipboard operation
apollo-cursor-pagination copied to clipboard

startCursor and endCursor should never be null

Open huw opened this issue 5 years ago • 3 comments

According to the Relay spec:

PageInfo must contain fields hasPreviousPage and hasNextPage, both of which return non‐null booleans. It must also contain fields startCursor and endCursor, both of which return non‐null opaque strings.

But in https://github.com/FleekHQ/apollo-cursor-pagination/blob/2552dfe1e4383973b6cef05272903d6da7aa972e/src/builder/index.js#L161, we don't return an appropriate fallback if the cursor is null (which happens when the query returns no results). This may (?) cause issues when integrating with Relay, but more importantly, isn't spec-compliant.

I think the appropriate fix (and I might take this on myself with a little more time) is to fall back to the cursor provided in the arguments (i.e. first or last)—these could be re-used by a client to request the theoretical 'next' page, should one become available between requests.

huw avatar Nov 09 '20 09:11 huw

Hey @huw, thanks for pointing that out!

I was taking a quick stab at it, and I think I can squeeze it in a new release today. However, the specs are not very clear on how to handle this "no results" scenario. Using before and after makes sense (I guess you meant that instead of first and last which are item counts instead of cursors). But the problem with that those are optional args, so we need to decide what to return if those are not supplied. Maybe just returning "" in those cases?

Let me know!

dmerrill6 avatar Nov 11 '20 16:11 dmerrill6

Cheers—thanks for your patience!

Yep, I meant before and after. I think you make a good point about the spec, though—there’s no guidance on what to do if there’s absolutely no data. I had a hunt around, and found this open PR on the spec—so I think we can watch that issue, and update this when there’s a solution in the spec.

huw avatar Nov 25 '20 06:11 huw

Sounds good!

I will keep this open to keep track of that discussion.

Cheers!

dmerrill6 avatar Nov 25 '20 12:11 dmerrill6