01 / 03

How to implement pagination in GraphQL?

Difficulty: 6/10
cursor-based pagination, offset pagination, Relay spec

Pagination in GraphQL allows you to efficiently manage large datasets by retrieving small chunks of data rather than fetching everything at once. There are two common approaches to implement pagination in GraphQL: Offset-Based Pagination and Cursor-Based Pagination.

Types of pagination:
  1. 1

    Offset-Based Pagination: This method uses and arguments to fetch a subset of data.

  2. 2

    Cursor-Based Pagination: This approach uses a to keep track of the current position in the dataset and fetch the next set of results.

Scenario Questions

0-2 years experience

  1. 1We have a simple GraphQL query to list products. How would you add pagination so the client can request the first 10 items and then the next page?
  2. 2If the client asks for page 3 using an offset argument but the underlying database returns only 5 rows, what would the GraphQL response look like?
  3. 3Can you show the shape of the GraphQL schema you’d expose for a paginated list of users?

2-5 years experience

  1. 1Our team switched from offset‑based to cursor‑based pagination to avoid duplicate rows when new items are inserted. Walk me through the changes you’d make to the resolver and schema, and why the old approach broke.
  2. 2During a load test the `after` cursor we generate sometimes causes the next page to miss records. How would you debug and fix this issue?
  3. 3We need to support both forward and backward pagination in a single query. What trade‑offs do you consider when designing the arguments and return type?

5-8 years experience

  1. 1At scale we have millions of rows and want to paginate efficiently across multiple services. How would you design a GraphQL pagination layer that minimizes DB load and supports caching?
  2. 2Our GraphQL gateway aggregates data from three micro‑services, each with its own pagination strategy. How would you reconcile them into a single consistent API for the client?
  3. 3Explain how you’d handle pagination when the underlying data can be reordered (e.g., sorting by a mutable field) without causing the client to see missing or duplicate items.

8+ years experience

  1. 1We’re planning a migration from a legacy REST endpoint that used page numbers to a new GraphQL API with cursor pagination. What architectural steps and backward‑compatibility concerns would you address?
  2. 2Across the organization we have dozens of GraphQL services. How would you establish a company‑wide pagination standard that balances performance, developer experience, and future extensibility?
  3. 3If we need to expose pagination for a federated schema where some subgraphs cannot generate stable cursors, what strategies would you employ to maintain a seamless client experience?

Follow-up Questions

  • How would you expose a total count without breaking pagination semantics?
  • What would you do if a client needs to jump to an arbitrary page number?
  • Can you discuss how caching interacts with paginated queries?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.