AshBackpex.LoadSelectResolver (Ash Backpex v0.1.2)
View SourceResolves which Ash loads and selects are needed for a given set of Backpex fields.
This module analyzes the fields configured in an AshBackpex LiveResource and determines which ones are:
- Attributes - Added to the
selectlist for efficient querying - Relationships, Calculations, or Aggregates - Added to the
loadlist
This separation allows the adapter to build efficient Ash queries that only fetch the data actually needed for the admin interface.
How It Works
The resolver examines each field name against the Ash resource schema:
- If the field is an attribute → add to
select - If the field is a relationship, calculation, or aggregate → add to
load - If the field doesn't exist on the resource → raise an error
Usage
This module is called internally by AshBackpex.Adapter to build queries.
You typically don't need to use it directly, but it can be useful for
debugging or custom adapter implementations:
fields = [
title: %{module: Backpex.Fields.Text},
author: %{module: Backpex.Fields.BelongsTo},
word_count: %{module: Backpex.Fields.Number}
]
{loads, selects} = AshBackpex.LoadSelectResolver.resolve(MyApp.Blog.Post, fields)
# loads => [:author, :word_count]
# selects => [:title]
Summary
Functions
Resolves field configurations into Ash loads and selects.
Types
Functions
@spec resolve(Ash.Resource.t(), field_list()) :: {[load()], [select()]}
Resolves field configurations into Ash loads and selects.
Given an Ash resource module and a keyword list of Backpex field configurations,
returns a tuple of {loads, selects} where:
loads- List of relationships, calculations, and aggregates to loadselects- List of attributes to select
Parameters
resource- AnAsh.Resourcemodulefields- Keyword list of field configurations (field name → config map)
Returns
A tuple {loads, selects} where both are lists of atoms.
Raises
Raises an error if a field name doesn't correspond to any attribute, relationship, calculation, or aggregate on the resource.
Examples
iex> fields = [title: %{}, author: %{}, word_count: %{}]
iex> AshBackpex.LoadSelectResolver.resolve(MyApp.Post, fields)
{[:author, :word_count], [:title]}