PhoenixApiToolkit.GenericRequestValidator.query_pagination

You're seeing just the function query_pagination, go back to PhoenixApiToolkit.GenericRequestValidator module for more information.
Link to this function

query_pagination(changeset, attrs, max_limit \\ 100, default_limit \\ 50)

View Source

Specs

query_pagination(
  map() | Ecto.Changeset.t() | schema(),
  map(),
  integer() | nil,
  integer() | nil
) :: Ecto.Changeset.t()

Validates the limit and offset query parameters of an index endpoint. If max_limit == nil, no maximum limit is enforced.

Examples

# the requested limit and offset should be in the range 0 - max_limit
iex> resource_schema() |> query_pagination(%{"limit" => 10}, 100)
#Ecto.Changeset<action: nil, changes: %{limit: 10}, errors: [], data: %{}, valid?: true>

iex> cs = resource_schema() |> query_pagination(%{"limit" => 150}, 100)
iex> cs.valid?
false

# a default limit can be set so that a default number of results is returned
iex> resource_schema() |> query_pagination(%{}, 100, 50)
#Ecto.Changeset<action: nil, changes: %{limit: 50}, errors: [], data: %{}, valid?: true>

# no max limit is enforced if `max_limit == nil`
iex> resource_schema() |> query_pagination(%{"limit" => 1_000_000}, nil)
#Ecto.Changeset<action: nil, changes: %{limit: 1000000}, errors: [], data: %{}, valid?: true>

# default limit can be disabled
iex> resource_schema() |> query_pagination(%{}, nil, nil)
#Ecto.Changeset<action: nil, changes: %{}, errors: [], data: %{}, valid?: true>