The Relay pagination specification says the following about PageInfo
:
It must also contain fields
startCursor
andendCursor
, both of which return non-null opaque strings.[...]
startCursor
andendCursor
must be the cursors corresponding to the first and last nodes in edges, respectively.
But what if I want to return zero items? There are lots of reason why a request to that specific endpoint would return an empty connection.
I don't see what values startCursor
and endCursor
should have in that case. The obvious answer is null
, but the spec explicitly says "non-null". What's up with that?
For what it's worth, I looked at roughly 15 articles about the topic of "graphql pagination" and all of those either ignore the issue or assign null
in the case of an empty list. So at this point it seems that the spec is just wrong or incompatible with the real world?
I Filed a bug on the relay Github: https://github.com/facebook/relay/issues/3708
It seems the canonical solution is to ignore the spec and make them non-nulll as both the JavaScript and java implementation do that.
Graphql-Relay-JS: https://github.com/graphql/graphql-relay-js/blob/3796e0904fbfe0dd86e540d5b4df236330c8a5e7/src/connection/arrayConnection.ts
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.