How should you paginate a GraphQL list field?
Two options:
- Offset/limit:
orders(offset: 40, limit: 20). Easy to implement but unstable when items are inserted or removed and slow at large offsets. - Cursor-based connections following the Relay spec:
orders(first: 20, after: "cursor")returningedges,node,cursorandpageInfowithhasNextPageandendCursor.
type OrderConnection {
edges: [OrderEdge!]!
pageInfo: PageInfo!
}
Cursors encode a stable, indexed sort key so pages do not skip or repeat items under concurrent writes. Always cap first and last to protect the server, make the connection a reusable pattern across fields, and document the sort order. Cursor pagination is more code but is the standard for feeds and anything that changes frequently.