fix(codegen): unwrap NewTypes before classifying return types for field selection#60
Merged
Torkan merged 1 commit intoash-project:mainfrom Mar 28, 2026
Merged
Conversation
Collaborator
|
Thanks a bunch! 🤩 |
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.
tl;dr
Fix missing call to unwrap new types, so fields get properly added/generated. Basically a one-line change - everything else is just tests.
Closes #59
Summary
When a generic action returns a
NewTypethat wraps:mapwith field constraints (e.g.,{:array, MyApp.Types.MySuggestion}), the generated TypeScript function is missing thefieldsparameter. However, the runtime RPC pipeline correctly requires field selection, resulting in a"requires_field_selection"error at runtime.Root Cause
ActionIntrospection.check_action_returns/1inaction_introspection.exdoes not callIntrospection.unwrap_new_type/2before classifying the return type. The NewType module (e.g.,MyApp.Types.MySuggestion) is not in@field_constrained_types([Ash.Type.Map, Ash.Type.Keyword, Ash.Type.Tuple]), soclassify_return_type/2returns{:error, :not_field_selectable_type}.Meanwhile, the runtime field processing in
field_selector.ex(line 116) does properly unwrap NewTypes before classification, sees the underlyingAsh.Type.Mapwith field constraints, and demands field selection — creating the mismatch.How to Reproduce
1. Define a NewType wrapping a map with field constraints
2. Define a generic action returning an array of this type
3. Expose via typescript_rpc
4. Run codegen and observe
The generated TypeScript function will NOT include a
fieldsparameter:5. Call the RPC and get runtime error
{ "type": "requires_field_selection", "message": "%{field_type} requires field selection", "shortMessage": "Field selection required", "vars": { "fieldType": "Field_constrained_type" } }Proposed Fix
Add
Introspection.unwrap_new_type/2call incheck_action_returns/1before classification:This mirrors the pattern already used in
field_selector.ex(line 116) and ensures codegen and runtime agree on whether field selection is required.Contributor checklist
Leave anything that you believe does not apply unchecked.