-
Notifications
You must be signed in to change notification settings - Fork 181
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
[RFC] Changes to connections spec and implementation #103
Comments
Any update on this? |
Regarding the non-nullability suggestions, that would mean that a error resolving the node within any edge in a connection would always propagate to invalidate the entire connection, and that there would be no flexibility on the implementing side to relax that behaviour while still conforming. As far as I know, right now nothing prevents a schema from asserting non-nullability for those fields on a particular edge type, if it wants or needs to. But to enforce that at the spec level for all edge types seems particularly restrictive in a very brittle way. |
@erydo, that's a very good point! I do agree that having the errors invalidate the entire connection is undesirable. Perhaps the non-nullability suggestions for nodes or edges aren't very good. 😅 I'm sure there would be a benefit to some of the non-nullability constraints as long as it doesn't force a node error to invalidate the entire connection. |
This will be a long one, please bear with me 😅 .
All ideas here are mostly relevant to pagination, and thus only the connections part of the Relay spec.
After much thought, going over #41, #58, #91, connection.js & the connection spec, and implementing the spec's algorithms for RethinkDB. I've come to a couple of ideas that I would love to hear some comments on (both from the community and the spec and GraphQL.js implementors).
If the ideas expressed here are of interest, I'd be honored to submit a PR.
Let's start with the simple ones:
Spec:
cursor
field be non-null for the edge type. Should every node have a cursor? It would make sense that if a node exists then there is a unique opaque identifier that can serve as a cursor. Which brings me to the next thought...node
type should not be restricted toObjectType
#41 @OlegIlyenko brought up the idea ofnodeType
being always nullable in the implementation. Would it make more sense for the node field in edges to be non-null?pageInfo
is required and its fieldshasNextPage
andhasPreviousPage
are required as well but these lose all meaning if theedges
field can be null.Implementation:
first
andlast
are validated inarrayconnection.js
(i.e., in the implementation of the paging algorithm). Would it make more sense to have this validation happen at the schema level (what I think the spec intends) by implementing anUnsignedInt
scalar and using that as arguments inforwardConnectionArgs
,backwardsConnectionArgs
andconnectionArgs
?cursorType
parameter toconnectionDefinitions
that would then use the given cursor type instead of aGraphQLString
?forwardConnectionArgs
,backwardsConnectionArgs
andconnectionArgs
could then be returned fromconnectionDefinitions
with the appropriate cursor type (removing the need of the previous thought of adding a schema validator... as long as the developer does use the returned objects).And that's it! Again, I will most likely be implementing most of these for our backend so I wouldn't mind at all to submit a PR. Also, I do understand that these might not be useful to others but I thought they could be so I wanted to hear people's thoughts.
Thanks for reading this huge wall of text. Please comment, criticize, and ask away! 🍺
Pagination Algorithm
... finally, here's the updated pagination algorithm. It should prove trivial to implement with any database as long as there is a way to get the count of records (I successfully implemented it in RethinkDB and can post that source code here if people want to see it). This would solve #58.
Arguments:
allEdges
,after
,before
,first
,last
Let hasPreviousPage be false.
Returns:
edges
,hasPreviousPage
, andhasNextPage
.There might be a more succinct way to write the algorithm but I'm 100% sure this works and I used the one from the spec as a baseline.
The text was updated successfully, but these errors were encountered: