Pagination
Implement efficient offset-based pagination with total counts.
Query Structureβ
query GetAtomsPage($limit: Int!, $offset: Int!) {
total: atoms_aggregate {
aggregate {
count
}
}
atoms(
limit: $limit
offset: $offset
order_by: { created_at: desc }
) {
term_id
label
created_at
}
}
Variablesβ
{
"limit": 20,
"offset": 40
}
This fetches page 3 (items 41-60) when using 20 items per page.
Best Practicesβ
- Always include order_by for consistent pagination
- Fetch total count using aggregates
- Use reasonable limits (10-100 items per page)
- Calculate offset as
(page - 1) * limit