# `GraphApi.Pagination`
[🔗](https://github.com/keenmate/microsoft_graph/blob/v1.0.0-rc.1/lib/graph_api/pagination.ex#L1)

Stream-based pagination for Microsoft Graph API responses.

Follows `@odata.nextLink` to lazily fetch subsequent pages.

## Examples

    {:ok, first_page} = GraphApi.Users.list(client: client)
    all_users = GraphApi.Pagination.stream(first_page, client: client)
      |> Enum.to_list()

# `collect_all`

```elixir
@spec collect_all(
  map(),
  keyword()
) :: {:ok, list()} | {:error, term()}
```

Collects all items from all pages into a single list.

A convenience wrapper around `stream/2` that eagerly fetches all pages.

# `extract_page`

```elixir
@spec extract_page(
  map(),
  keyword()
) :: {list(), String.t() | nil}
```

Extracts page data from a Graph API response.

Returns `{items, next_link}` where `items` is the list of items from `"value"`
and `next_link` is the URL for the next page (or nil).

Optionally accepts an `as:` module to cast each item.

# `stream`

```elixir
@spec stream(
  map(),
  keyword()
) :: Enumerable.t()
```

Creates a lazy `Stream` that follows `@odata.nextLink` to yield all items.

Takes the first page response body and options (must include `:client`).
Optionally accepts `:as` to cast each item into a schema/view struct.

## Examples

    {:ok, page} = GraphApi.Users.list(client: client)
    stream = GraphApi.Pagination.stream(page, client: client)
    all = Enum.to_list(stream)

    # With schema casting
    stream = GraphApi.Pagination.stream(page, client: client, as: GraphApi.Schema.User)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
