⬡ GraphQL Advanced

What is the Relay specification for GraphQL — Node interface, Connection/Edge pagination?

Answer

The Relay spec defines opinionated GraphQL conventions that enable Relay client's powerful caching and pagination features, but have been widely adopted beyond Relay. The Node interface requires every object type to implement interface Node { id: ID! } with a globally unique ID, enabling the root node(id: ID!): Node query to refetch any object by ID. Connection-based pagination wraps list fields: instead of posts: [Post], you have posts(first: Int, after: String): PostConnection where PostConnection has edges: [PostEdge] and pageInfo. Each PostEdge has a node (the actual Post) and a cursor (opaque pagination token). The pageInfo object provides hasNextPage, hasPreviousPage, startCursor, and endCursor. This verbose but powerful structure enables stable cursor-based pagination and per-edge metadata.