Skip to content

Add query parameter support for read actions#7

Closed
barnabasJ wants to merge 15 commits intoagentjido:mainfrom
barnabasJ:query-parameters
Closed

Add query parameter support for read actions#7
barnabasJ wants to merge 15 commits intoagentjido:mainfrom
barnabasJ:query-parameters

Conversation

@barnabasJ
Copy link
Copy Markdown

@barnabasJ barnabasJ commented Mar 20, 2026

Summary

Closes #4

Expose Ash query parameters (filter, sort, limit, offset) in generated Jido action schemas for read actions. The field validation logic (filterable?/sortable? checks, type rejection, aggregate resolution) is largely adapted from ash_json_api.

  • Add action_parameters DSL option per action and read_action_parameters on all_actions, following the existing load/read_load naming pattern
  • All query params enabled by default for read actions, opt-out via action_parameters: [:limit] etc.
  • Field validation adapted from ash_json_api: rejects array types, unions, embedded types, unwraps NewType; includes public attributes, calculations (with expressions), and aggregates
  • Runtime applies params via Ash.Query.filter_input/2, sort_input/2, limit/2, offset/2
  • Ash natively handles max_page_size clamping and default_limit

Test plan

  • 24 integration tests covering schema generation, filtering, sorting (all 6 directions), limit, offset, combined params, action arg coexistence, string keys, type rejection (array, private, non-filterable, non-sortable)
  • 3 existing tests updated for new read action schema shape
  • mix test — 186 tests, 0 failures
  • mix compile --warnings-as-errors — clean
  • mix format --check-formatted — clean

Add :action_parameters to JidoAction and :read_action_parameters to
AllActions, allowing users to configure which query parameters (filter,
sort, limit, offset) are exposed for read actions. Propagate
read_action_parameters through the transformer for all_actions expansion.
Read actions now include filter, sort, limit, and offset in their
NimbleOptions schema. Schema docs list only public filterable/sortable
attributes. The action_parameters option controls which params are exposed.
Split query params (filter, sort, limit, offset) from action params
before building the Ash query. Apply each via Ash.Query functions.
Handles both atom and string keys for LLM tool call compatibility.
Tests cover schema generation (including action_parameters restriction),
filtering by equality and comparison, sorting, limit, offset, combined
parameters, action args coexisting with query params, empty params as
no-ops, and string key support.
Update assertions that previously expected read actions to have no query
parameters, now that filter/sort/limit/offset are included by default.
Skip sort entries with missing field key instead of interpolating nil.
Default nil direction to "asc" explicitly instead of relying on
to_string(nil) falling through.
Set default [:filter, :sort, :limit, :offset] on action_parameters and
read_action_parameters in both DSL schema and struct definitions. This
eliminates the || fallback expressions in the generator.
Ensures the transformer never produces nil for action_parameters,
matching the struct default and non-nilable typespec.
Remove unnecessary atom_key alias in split_query_params. Add test
for sort with string keys to match filter/limit string key coverage.
…rameters

Add explanatory comments to split_query_params, maybe_apply_sort,
build_query_param_schema, and the query param pipeline in execute_action.
Validate that action_parameters is only customized on read actions,
matching the existing :load validation pattern.
Test asc, desc, asc_nils_first, desc_nils_last, and multi-field sort.
Add nullable category attribute to test resource for nil ordering.
Pass {field, direction} tuples directly to Ash.Query.sort_input/2
instead of converting to prefixed strings. This supports all 6 Ash
sort orders including desc_nils_first and asc_nils_last which the
string prefix format cannot express. Add tests for all 6 directions.
Use Ash.Resource.Info pattern from ash_json_api: include public
calculations with expression implementations alongside attributes in
filterable/sortable field lists. Call Code.ensure_compiled! before
function_exported? to handle unloaded modules.
Port ash_json_api's field validation pattern: reject array types,
unions, embedded types, and NewType wrapping. Include public aggregates
alongside attributes and calculations. Use Transformer.get_entities
for compile-time introspection with ash_json_api-style type guards.
Pass field names as-is to Ash.Query.sort_input (Ash resolves strings
and atoms). Normalize direction via a fixed allowlist instead of
String.to_existing_atom, defaulting invalid values to :asc.

Add tests verifying array types, private attributes, non-filterable,
and non-sortable fields are correctly excluded from schemas.
Munksgaard added a commit to Munksgaard/ash_jido that referenced this pull request Apr 1, 2026
Unify PR agentjido#5 (Munksgaard) and PR agentjido#7 (barnabasJ) approaches:

- Rename action_parameters -> query_params (per-action DSL option)
- Rename read_action_parameters -> read_query_params (all_actions DSL option)
- Add Query Parameters section to README.md with examples and config
- Add Querying and Filtering section to getting-started.md guide
- Update DSL option tables in both docs
- Remove 'Add pagination or query-layer magic' from What It Does Not Do

Keeps PR agentjido#7's core logic: compile-time field validation, string key
support, map-based sort format, and ash_json_api-style type checks.
Uses PR agentjido#5's naming convention and documentation style.

All 186 tests pass. mix quality clean.
@mikehostetler
Copy link
Copy Markdown
Contributor

Superseded by #15. We carried forward the key runtime ideas from this branch into the merged read-action query parameter implementation on April 1, 2026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Support ash query parameters in e.g. read actions to enable filtering, sorting, limiting and so on.

2 participants