Two strategies: offset-based (limit/offset) and cursor-based. GraphQL has no built-in pagination, but the community standard is the Relay Connection spec, which formalizes cursor pagination.
Two strategies: offset-based (limit/offset) and cursor-based. GraphQL has no built-in pagination, but the community standard is the Relay Connection spec, which formalizes cursor pagination.
items(limit: 10, offset: 20)) is simple but breaks on live data: if a row is inserted while the user pages, items shift and you see duplicates or gaps. It also gets slow at deep offsets (the DB still scans skipped rows).A connection wraps the list in edges (each with a cursor and node) plus pageInfo:
posts Int, String PostConnection
PostConnection
PostEdge
PageInfo
PostEdge
String
Post
PageInfo
String
Boolean
rows = db..({ : args., : args. + });
hasNextPage = rows. > args.;
page = rows.(, args.);
{
: page.( ({ : p, : (p.) })),
: { : page.(-) && (page.(-).), hasNextPage },
};
The cursor is opaque — usually a base64 of the sort key — so clients treat it as a token, not a number.
Choosing offset vs cursor shows you understand consistency under concurrent writes and deep-page performance. Knowing the Relay connection shape matters because Apollo/Relay clients have built-in cache handling for it.
A library of IT interview questions with detailed answers — from Junior to Senior.
Donate