-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Relay spec: Cursor nullability is defined poorly, PageInfo doesn't use Cursor #3826
Comments
To clarify this a bit, having a nullable cursor on an edge (as allowed by the current spec) conflicts with the rest of the spec. In particular, if an edge could have a null cursor then the following issues would happen:
If any implementation has a valid reason for wanting to support an edge with a null cursor, that could be handled by defining the cursor type as a custom scalar and serializing the null cursor as a sentinel scalar value instead (such as an empty string). This means that there is no reason why cursors cannot be required to be nonnull. Footnotes |
graphql/graphql-relay-js#243 I don't use relay just saw these two issues and though they are related, sorry if I'm wrong. |
I think you're a bit too worried about this, it's pretty obvious that the intent is to use a unique string value for every position in the data. It's not necessary to require that I'm sure |
The current spec defines a
Cursor
like so:This itself is a little weird. Why can an edge type have a nullable cursor? The only reasonable meaning for a null cursor is to represent a position that does not correspond to any edge or lie in between edges. The most obvious usage here is when returning a
PageInfo
when there are no edges at all, the start/end cursors would then benull
.To that end,
cursor
should be defined as strictly Non-Null, and then the places that use cursors would then specify either a nullable or a non-null cursor. The Edge Type fieldcursor
would itself specify that it is a non-null cursor.On that note, the current spec defines
PageInfo
's fields like so:This type has two cursors, and yet it's not even using the cursor type as defined earlier. The introspection for this type also explicitly uses nullable strings without any note that other types are possible (as compared with the introspection for Cursor which has a comment indicating that it represents a cursor type of
String!
but other types are possible).This is a problem because it means in any strongly-typed language, the
startCursor
andendCursor
fields are incompatible with the forward/backward pagination arguments and with thecursor
field on an edge.PageInfo
should instead be defined such thatstartCursor
andendCursor
are nullable cursor types, where null is used if there is no data. This is similar to today but it just means changing "opaque string" into "cursor type" and putting a comment in the introspection indicating that this example shows the cursor type as being aString
.The text was updated successfully, but these errors were encountered: