05

Pagination is a data structure, not a hand-written loop

GraphQL connections model a list as edges with opaque cursors, plus pageInfo. Relay keeps the connection as a record in the store and appends each page to it. Load a few pages and watch the strip grow, colored by the request that brought each edge in.
Fetching with Relay…
  • why it mattersCursors are stable positions. Inserting a post at the top doesn't shift the next page the way offset pagination does.
  • why it mattersOne fragment covers the first render and every later page. The compiler derives the pagination query, so the two can't drift apart.
  • why it mattersBecause the connection lives in the store, a mutation can append or prepend an edge (@appendEdge) and the list updates without a refetch.