feat: Exclude resource calculations from resource struct with `field?: false` option
Improvements
- Add
field?option toAsh.Resource.CalculationDSL - Exclude
field?: falsecalculations from Resource struct and direct loading, but still usable in expressions - Add validation that returns
Ash.Error.InvalidLoaderror when loading afield?: falsecalculation directly - Update calculations docs with explanation of
field?option
We could probably do the same for aggregates once this is done.
#2242
Contributor checklist
Leave anything that you believe does not apply unchecked.
- [x] I accept the AI Policy, or AI was not used in the creation of this PR.
- [ ] Bug fixes include regression tests
- [ ] Chores
- [ ] Documentation changes
- [x] Features include unit/acceptance tests
- [ ] Refactoring
- [ ] Update dependencies
ok, the validation is in and you now get an InvalidLoad error when you attempt to load a field?: false resource calculation.
Just had a thought: we may actually have a bit of an issue here 😢
Specifically, AshGraphql and AshJsonApi will need to be updated to support this, by not allowing loads for these non-loadable calculations. We'll want PRs for those done before we release this.
Just had a thought: we may actually have a bit of an issue here 😢
Specifically, AshGraphql and AshJsonApi will need to be updated to support this, by not allowing loads for these non-loadable calculations. We'll want PRs for those done before we release this.
No experience with those packages, but I'll take a look at them.
Both api libraries only expose public?: true calculations. So, I made a small change to have public_calculations and public_calculation only return back field?: true calculations.
Do you see any cases where a field?: false calculation should be exposed outside the resource?
Hmm...yes. It could be supported in filters exposed over GraphQL for example without being exposed as a field.