facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.39k stars 1.82k forks source link

GraphQL Cursor Connections Specification return Nodes without Edges #3850

Open sonatard opened 2 years ago

sonatard commented 2 years ago

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

Vishwaas commented 4 months ago

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