Pagination Basics
Every collection query acceptsfirst and skip parameters:
| Parameter | Type | Default | Maximum | Description |
|---|---|---|---|---|
first | Int | 100 | 1000 | Number of entities to return |
skip | Int | 0 | 5000 | Number of entities to skip |
The absolute maximum for
first is 1000 entities per query. For paginated UI tables, use a page size of 25 and increment skip by 25 per page. The skip parameter has a soft cap of 5000 — queries beyond this offset may time out on hosted services.Sorting
UseorderBy and orderDirection together:
orderDirection accepts asc (ascending) or desc (descending). If omitted, defaults to asc.
Sortable fields include any scalar field on the entity (BigInt, Int, String, Bytes). Sorting by BigDecimal (e.g., sharePrice) is also supported.
Filtering with where
The where clause filters entities by field values. The Graph supports suffix-based operators:
Comparison Operators
| Suffix | Meaning | Example |
|---|---|---|
| (none) | Equals | status: "OPEN" |
_not | Not equal | status_not: "OPEN" |
_gt | Greater than | notional_gt: "1000000000" |
_gte | Greater than or equal | openTimestamp_gte: "1700000000" |
_lt | Less than | notional_lt: "10000000000" |
_lte | Less than or equal | closeTimestamp_lte: "1700100000" |
_in | In array | status_in: ["CLOSED_MATURITY", "LIQUIDATED"] |
_not_in | Not in array | status_not_in: ["OPEN"] |
_contains | Contains (Bytes) | pairId_contains: "0xab" |
Combining Filters
All conditions in awhere clause are ANDed:
Time Range Queries
Combine_gte and _lte on timestamp fields to query date ranges:
Indexed Fields
Queries filter most efficiently on indexed fields. The subgraph indexes these fields with@index:
| Entity | Indexed Fields |
|---|---|
| Position | account, status, openTimestamp |
| OracleRound | isLatest |
| VaultEvent | timestamp |
| PoolTransaction | timestamp |
Pagination Patterns
Offset Pagination (Simple)
Suitable for UI tables with page numbers:Cursor Pagination (Large Datasets)
For datasets larger than 5000 entities, use the last entity’s sort field as a cursor:skip cap and performs better for deep pagination.
Fetching All Open Positions
When you need all open positions (e.g., for keeper batch operations), paginate with the cursor pattern:Derived Fields
TheAccount.positions field uses @derivedFrom, meaning it performs a reverse lookup at query time. Derived fields support the same pagination parameters:
Related Pages
Query Examples
Ready-to-use query patterns.
Schema Reference
Entity definitions and field types.
Data Source Guide
Choosing between subgraph and RPC.