Calculations: Add `field?: false` option to exclude from Resource struct fields
- Dominant language
- Elixir
- Stars
- 2.5k
- Forks
- 422
- Avg merge
- 23h 26m
- Merged PRs (30d)
- 46
Description
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
### AI Policy
- [x] I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.
### Is your feature request related to a problem? Please describe.
Currently, all calculations defined on a resource become struct fields. Sometimes you want to create calculation that are only meant to be composed with other calculations within the resource and don't need to be included in the struct as fields.
### Describe the solution you'd like
Introduce a `field?: false` option (defaulting to true) that:
- Excludes the calculation from the resource struct fields. Reducing struct field clutter.
- Prevents the calculation from being directly loadable via queries
- Still allows the calculation to be referenced in expressions within the resource
- Maintains all existing calculation functionality
**Example**
```elixir
calculate :average_things, :float, expr(sum_of_things / count_of_things)
calculate :count_of_things, :integer, expr(count(things)) do
field? false
end
calculate :sum_of_things, :integer, expr(sum(things, field: :value)) do
field? false
end
```
In this example:
- Only :average_things would be loadable and appear in the struct
- :count_of_things and :sum_of_things remain available for internal composition
### Describe alternatives you've considered
_No response_
### Additional context
Suggested by [Zach in Discord](https://discord.com/channels/711271361523351632/711271361523351636/1400287775361732810) as a neat feature to support
Contributor guide
Research direction
Start with the resource calculation DSL around the `calculate` declarations and trace how calculations become struct fields and query-loadable fields. Verify the existing expression composition behavior, then check that `field?: false` excludes only the calculation from struct fields and direct loading while preserving references from `expr(...)` calculations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100