Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse Fieldsets without calculations #524

Open
hubertnnn opened this issue Jun 23, 2021 · 2 comments
Open

Sparse Fieldsets without calculations #524

hubertnnn opened this issue Jun 23, 2021 · 2 comments
Labels

Comments

@hubertnnn
Copy link

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:

  1. Know what fields were requested inside the transformer
  2. 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.

@matthewtrask
Copy link
Contributor

hmm I thought I had a work around, but I can see what you are talking about.

since we are working on a 1.0 now, this could definitely be worked on.

I think the best way, as I see it now, would be an added parameter to the transform method, but Im not totally sold on that one.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 4 weeks if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants