The default_fields defined at the root level in the json_api block of AshJsonApi is not returning Ash calculations in the JSON response. However, defining default_fields at the route level works as expected. Specifically, the calculation :graphs is not included in the response when using root-level default_fields.
To Reproduce
Define a JSON API with default_fields at the root level including an Ash resource attribute :enabled and an Ash calculation :graphs.
Make a call to the API and observe that the :graphs calculation is not included in the JSON response.
Uncomment the default_fields at the route level and observe that the :graphs calculation is now included in the response.
Example code:
json_api do
type "widget"
default_fields([:enabled, :graphs])
routes do
base("/widgets")
index :read
get :get_by_id do
route("/:id")
# default_fields([:enabled, :graphs])
end
end
end
Expected behavior
The default_fields defined at the root level should return both Ash resource attributes and Ash calculations in the JSON response. But it only returns the attributes, in turn the commented default_fields in the route work as expected.
The default_fields defined at the root level in the json_api block of AshJsonApi is not returning Ash calculations in the JSON response. However, defining default_fields at the route level works as expected. Specifically, the calculation :graphs is not included in the response when using root-level default_fields.
To Reproduce
Define a JSON API with default_fields at the root level including an Ash resource attribute :enabled and an Ash calculation :graphs.
Make a call to the API and observe that the :graphs calculation is not included in the JSON response. Uncomment the default_fields at the route level and observe that the :graphs calculation is now included in the response.
Example code:
Expected behavior
The default_fields defined at the root level should return both Ash resource attributes and Ash calculations in the JSON response. But it only returns the attributes, in turn the commented default_fields in the route work as expected.
Runtime
Elixir version: 1.16.3 Erlang version: erts-13.2.2.9 OS: MacOS Ash version: