Helpers for traversing Relay-style cursor pagination over the Gaiia API.
Connections expose edges, nodes, pageInfo, and totalCount. Each edge
contains its cursor and node; totalCount is the total across all pages,
not the number of items on the current page. Page info contains
hasNextPage, hasPreviousPage, startCursor, and endCursor.
Forward traversal uses first and after, following hasNextPage and
endCursor. Backward traversal uses last and before, following
hasPreviousPage and startCursor. Backward traversal yields the nodes or
edges within each page in the order returned by the server, while traversing
pages from newest to oldest.
The general page-size default is 50 and maximum is 250. Individual fields can override both values, so this library deliberately does not cap or validate page sizes.
Example
query = ~S"""
query Accounts($first: Int, $after: String) {
accounts(first: $first, after: $after) {
nodes { id name }
pageInfo { hasNextPage endCursor }
}
}
"""
client
|> Gaiia.Pagination.stream(query, %{"first" => 50}, path: ["accounts"])
|> Stream.take(200)
|> Enum.to_list()
Summary
Functions
Stream all edges from a paginated GraphQL field.
Stream all nodes from a paginated GraphQL field.
Types
Functions
@spec edges(Gaiia.Client.t(), String.t(), map(), opts()) :: Enumerable.t()
Stream all edges from a paginated GraphQL field.
Each yielded edge includes the server-provided cursor and node, allowing
callers to save an item cursor and resume by supplying it as the initial
after or before variable. Accepts the same options and traversal ordering
as stream/4.
@spec stream(Gaiia.Client.t(), String.t(), map(), opts()) :: Enumerable.t()
Stream all nodes from a paginated GraphQL field.
In backward mode, nodes retain the order returned within each page while pages are traversed from newest to oldest.
Options
:path— A list of keys describing where the connection lives inside thedatapayload, for example["accounts"]. Required.:direction—:forward(default) or:backward.:cursor_variable— Cursor variable name. Defaults to"after"for forward traversal and"before"for backward traversal.