Skip to content
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

Closed
wants to merge 1 commit into from
Closed

feat: PageInfo is nullable #62

wants to merge 1 commit into from

Conversation

maraisr
Copy link

@maraisr maraisr commented Jan 17, 2022

PageInfo is a nullable entity, making all members NonNull please see https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo.Fields

@sikanhe
Copy link
Owner

sikanhe commented Jan 17, 2022

@n1ru4l You are familiar with Relay, can you help take a look?

@sikanhe sikanhe requested a review from n1ru4l January 17, 2022 02:59
@sikanhe
Copy link
Owner

sikanhe commented Jan 17, 2022

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

@maraisr
Copy link
Author

maraisr commented Jan 17, 2022

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
Copy link
Collaborator

@n1ru4l n1ru4l Jan 18, 2022

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.

Copy link
Author

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,
Copy link
Collaborator

@n1ru4l n1ru4l Jan 18, 2022

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

java too: https://github.com/graphql-java/graphql-java/blob/1ee9630c7d25ccb55a5b1d9b1ccf7bf7895a8c7f/src/main/java/graphql/relay/Relay.java#L54


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.

Copy link
Author

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?

@sikanhe
Copy link
Owner

sikanhe commented Jan 18, 2022

Closing this as all other relay implementations do the same

@sikanhe sikanhe closed this Jan 18, 2022
@maraisr maraisr deleted the non-null-pageinfo branch January 18, 2022 21:18
@maraisr
Copy link
Author

maraisr commented Jan 18, 2022

Just because they all do the same, doesn't make it right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants