-
Notifications
You must be signed in to change notification settings - Fork 347
Description
I recently got myself into a situation, where I don't want to always calculate one of the attributes.
In fact I only want it to be calculated when explicitly asked for (since the cost to do so)
Sparse fieldsets are a nice way to handle this, but there is no way to know inside the transformer if a field was requested or not.
On top of that JsonApi specification says that:
If a client does not specify the set of fields for a given resource type,
the server MAY send all fields, a subset of fields, or no fields for that resource type.
Currently its not really possible to send anything but all fields.
Would be nice to have a way to:
- Know what fields were requested inside the transformer
- Have a way to make a field missing by default.
One way to do it might be to include the selected field list as second parameter of transform() function and let the transformer handle filtration.
Another way might be to have a similar system to includes with $defaultAttributes, $availableAttributes and includeXXX() that would be merged with results of transform() function.