Provides unified resource field type lookup.
This module centralizes the logic for looking up field types from Ash resources, supporting attributes, calculations, relationships, and aggregates.
Variants
get_field_type_info/2- Looks up any field (public or private)get_public_field_type_info/2- Looks up only public fields
Both return {type, constraints} tuples, with {nil, []} for unknown fields.
Summary
Functions
Gets the resolved type for an aggregate field.
Gets the type and constraints for any field on a resource.
Gets the type and constraints for public fields only.
Resolves aggregate type info including constraints.
Functions
Gets the resolved type for an aggregate field.
Aggregates can have computed types based on the underlying field type. This function returns the fully resolved aggregate type.
Examples
iex> get_aggregate_type_info(MyApp.User, :todo_count)
{Ash.Type.Integer, []}
Gets the type and constraints for any field on a resource.
Checks attributes, calculations, relationships, and aggregates in order. Uses non-public Ash.Resource.Info functions to access all fields.
Examples
iex> get_field_type_info(MyApp.User, :name)
{Ash.Type.String, []}
iex> get_field_type_info(MyApp.User, :todos)
{{:array, MyApp.Todo}, []}
iex> get_field_type_info(MyApp.User, :unknown)
{nil, []}
Gets the type and constraints for public fields only.
Checks public attributes, calculations, aggregates, and relationships in order. Used for output formatting where we only want publicly accessible fields.
Examples
iex> get_public_field_type_info(MyApp.User, :name)
{Ash.Type.String, []}
iex> get_public_field_type_info(MyApp.User, :private_field)
{nil, []}
@spec resolve_aggregate_type_info(module(), Ash.Resource.Aggregate.t()) :: {atom() | tuple() | nil, keyword()}
Resolves aggregate type info including constraints.
For first aggregates with nil type, we need to look up the field on
the destination resource to get the actual type and constraints.
Examples
iex> agg = Ash.Resource.Info.aggregate(MyApp.User, :first_todo_title)
iex> resolve_aggregate_type_info(MyApp.User, agg)
{Ash.Type.String, []}