relay icon indicating copy to clipboard operation
relay copied to clipboard

GraphQL Cursor Connections Specification return Nodes without Edges

Open sonatard opened this issue 4 years ago • 1 comments

The Modern Relay in the GraphQL Cursor Connections Specification explains that Edge's cursor is not used.

As this spec was created with Relay Classic in mind, it’s worth noting that Relay Legacy did not define startCursor and endCursor, and relied on selecting the cursor of each edge; Relay Modern began selecting startCursor and endCursor instead to save bandwidth (since it doesn’t use any cursors in between). https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo.Fields

If that's the case, we don't need Edge, and why not just return an array of Node? I feel that Edge is an unnecessary type hierarchy.

If the GraphQL Cursor Connections Specification does not change, it is difficult for the client library utility to support Nodes. https://www.apollographql.com/docs/react/pagination/cursor-based/#relay-style-cursor-pagination

Schema samples

GitHub and Shopify Admin API returns an array of Node in the Connection.

GitHub Shopify
shopify github
スクリーンショット 2022-05-18 20 30 48 スクリーンショット 2022-05-18 20 31 29

https://shopify.dev/api/release-notes/2022-04

Improvements to GraphQL connections As of API version 2022-04, we've added a nodes field on the Connection object. When you only query node on edges, you can simplify the query. We've also added the startCursor and endCursor fields on the PageInfo object, which allows you to simplify the shape of return data for pagination.

For more information, refer to Paginating results with GraphQL.

New fields

nodes field was added to Connection object startCursor field was added to PageInfo object endCursor field was added to PageInfo object

sonatard avatar Mar 24 '22 14:03 sonatard

Is there an effort by relay to move in this direction?

Vishwaas avatar Jun 11 '24 12:06 Vishwaas