Add query parameter support for read actions#7
Closed
barnabasJ wants to merge 15 commits intoagentjido:mainfrom
Closed
Add query parameter support for read actions#7barnabasJ wants to merge 15 commits intoagentjido:mainfrom
barnabasJ wants to merge 15 commits intoagentjido:mainfrom
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
action_parametersDSL option per action andread_action_parametersonall_actions, following the existingload/read_loadnaming patternaction_parameters: [:limit]etc.Ash.Query.filter_input/2,sort_input/2,limit/2,offset/2max_page_sizeclamping anddefault_limitTest plan
mix test— 186 tests, 0 failuresmix compile --warnings-as-errors— cleanmix format --check-formatted— clean