Include calculation in response alongside public fields?
โ SolvedAshJsonApi
I have a resource exposed over Ash JSON API, and so far I've been relying on the fact that public attributes are sent by default in the response. Now I've added a calculation, which I've made public.
I realized that it's not automatically added to the response by default (which makes sense, as calculations may be expensive), and it looks like I have two options: - Use
default_fields
default_fields
on the resource to include the calculation. But then I also have to explicitly list all the other public attributes. - Let the client ask for the fields they want, including the calculation.
I was really hoping for a third option, which would let me somehow specify that I'd like to include this calculation by default alongside the public fields (without having to list them). My worry is I'll forget to add new public fields to this list, or that i'll accidentally add a field which isn't public.
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.