-
Notifications
You must be signed in to change notification settings - Fork 38
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
Always return "included" where "include" has been requested (v1.1) #35
Comments
@noetix, great addition 👍 But actually, I can't know if "include" parameter has been requested or not regarding data (Maybe I'm missing something). Maybe 2 possible ways:
|
You're right, this is tough when you're decoupled from the incoming request. Part of the spec is also to only include requested includes. The current implementation would return any includes in your serialized data. With that in mind, option 1 with a minor tweak would be my preferred option. Instead of marking include as true, pass a list of resource types that should be included. That way the library can ignore included data that has not been requested. e.g.
In this example, any relationship data found for author would not be included. Passing in request options would be easy. You could even allow for the configuration when registering type. |
You're right, it's much better than I always thought that, for your exemple, any relationship data for author would never be populated before passing the data through serializer, so it would never appeared in included. I think that it's the responsability of any database or something else to filter the wanted data before responding it (there is fewer things to manipulate, filter, etc... best performance). Do you have such case of embedded author on article, even if it has not been requested before using the serializer ? I will investigate further on the possibility of such option. Do you know a library that can do such filtering ? Thanks ! |
Interesting addition, thanks for the report @noetix! E.g. if the database payload for The next problem is: relationship-names can differ from related resource types. E.g. an That said, I would favour to go with a simple |
Agreed. If its going to be highly complex to filter results that the database layer shouldn't be returning then the problem should stay with the database layer. 👍 for |
I made a quick try of whitelisting includes with such Seems to be not as complex as it is. @noetix, could you make a try, and tell me if it corresponds to your needs ? |
@danivek any movement on this? There are definitely cases where I don't want to include the data, but would still like the relationship to be present. |
@danivek Echoing @jamesdixon question |
@EmirGluhbegovic, I need some feedbacks on branch include-filter-test could you make a try, and tell me if it corresponds to your needs ? |
@danivek I am also interested in this concept of whitelisting a chain of includes. Wondering what the status of this is. |
I have now very often in my code:
I would love to write
Just because it is less code. ;-) |
When requesting results with included data, the response should always have the
included
top-level key. The response structure should not change depending on the data sourced to generate the response.While this rule is [now] part of the v1.1 spec, it'd be fantastic if it was implemented as is. I don't think its harmful for v1.0 spec consumers.
Rule: json-api/json-api@c762b92
The text was updated successfully, but these errors were encountered: