Declares the query params of controller actions, so that the generated route
helpers type their query option.
defmodule MyAppWeb.TaskController do
use MyAppWeb, :controller
use Typelizer.Query
query :index,
page: {:optional, :integer},
status: {:optional, {:enum, [:todo, :doing, :done]}},
tags: {:optional, {:list, :string}}
def index(conn, params), do: ...
endroutes.task.index({ query: { page: 2, status: "todo" } }); // ok
routes.task.index({ query: { stauts: "todo" } }); // compile errorQuery keys stay as written (snake_case), because Phoenix reads them as written.
Only types are generated: the controller still casts and validates params.
Actions without a declaration keep Record<string, unknown>.
A LiveView module can declare the query params of its live actions the same way.
See the Route helpers guide.
Summary
Functions
Declares the query params of an action: a keyword list of param name → type spec.
Wrap a spec in {:optional, spec} for a param that may be left out.