-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: PageInfo is nullable #62
Conversation
@n1ru4l You are familiar with Relay, can you help take a look? |
I remmeber this - I ported the behavior from graphql-js graphql/graphql-relay-js#243 The reason cursors are nullable is because it's unclear what they should be when array is empty. But if array is empty, we can still get information about whether there is next page. So I am not sure that returning null for PageInfo is correct when array.length === 0 |
The spec clearly says the cursors must be non-null, see link I attached in pr description. The field is aptly named "PageInfo" alluding to the fact it's information about a page, if there is no page — aka edges is empty — then the field (PageInfo) is null. There is chatter about the repo you linked "graphql-relay-js" so still waiting on an official answer. For now, maybe our best bet is to check what our c# friends are doing with HotChocolate. |
@@ -430,7 +432,7 @@ enum Episode { | |||
\\"\\"\\"A connection to a list of items.\\"\\"\\" | |||
type CharacterConnection { | |||
\\"\\"\\"Information to aid in pagination.\\"\\"\\" | |||
pageInfo: PageInfo! | |||
pageInfo: PageInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://relay.dev/graphql/connections.htm#sec-Connection-Types.Fields.PageInfo
A “Connection Type” must contain a field called
pageInfo
. This field must return a non-null PageInfo object, as defined in the “PageInfo” section below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're a tad hypocritical here mate. How can you drop the spec on me here and ignore it on the other moment?
endCursor: array[array.length - 1].id, | ||
edges, | ||
pageInfo: edges.length > 0 ? { | ||
endCursor: edges[edges.length - 1].cursor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of an empty list, I tend to use ""
as the start/end cursor values, as the pageInfo
field is non-nullable per spec. However, there is ambiguity on what to do.
See https://stackoverflow.com/q/70448483, facebook/relay#3708
Hot Chocolate seems to use nullable end and start cursors: https://github.com/ChilliCream/hotchocolate/blob/c479c10343f22328f708dc4d8e80f98a76bbf518/src/HotChocolate/Core/src/Types.CursorPagination/PageInfoType.cs#L29-L39
Furthermore, ID != cursor, so it might make sense to to have some kind of cursorFromRecord
function. IMHO this can be part of a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're just giving me opinions.
The spec clearly says what must happen?
Closing this as all other relay implementations do the same |
Just because they all do the same, doesn't make it right. |
PageInfo is a nullable entity, making all members NonNull please see https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo.Fields