Closed bjornharrtell closed 7 years ago
Implementation seems to work in some limited tests. Some test cases was failing but I've now managed to fix them. @joukevandermaas this is now ready for review.
There are two behavioral changes that I've seen with this PR:
Before it seems the default behavior was to return all relationship data as included. With this PR relationship data will not be included by default and must be explicitly requested with the include param. I think this behavior was added intentionally by @yohanmishkin but I'm not sure about the reasoning.
Before empty relationships was included. With this PR they are not. I can't find if the spec says one of these two is the correct behavior.
@joukevandermaas can you clarify "Is there some way to dis-allow the client from including resources? The endpoint still has to support it for it to work."?
@bjornharrtell
[AllowClientInclude]
attribute on the action method, or a parameter to the BelongsTo
and HasMany
functions in ApiResource
.This is also what I meant by "is there some way to dis-allow the client from including resources? The endpoint still has to support it for it to work." The API writer should be able to control whether the client can or cannot include a given relationship.
links
hash that allowed clients to fetch the data async).{
"attributes": { ... },
"relationships": {
"job": {
"links": {
"related": "http://.../job",
"self": "http://.../relationships/job"
}
}
}
}
I think that should still happen if the client did not ask to include the resource or if the resource property does not exist on the model.
Thanks for the explanations, I think it makes sense.
We had some heavy objects with many nested relationships so that's why I made inclusions opt-in by default, but it makes sense to me to avoid introducing breaking changes.
To be honest, I'm not positive why I removed empty relationships, but I think it may have been ember-cli-mirage inspired.
Ready for review once more @joukevandermaas. Things done:
I've refactored to keep the state of DisableDefaultIncluded
on IncludedContext
instead of QueryContext
, and assuming false
if IncludedContext
is null
. Ready for review yet again @joukevandermaas.
@bjornharrtell Thanks so much for seeing this through! I'm going to merge this and publish a new beta release with the changes.
@yohanmishkin Thanks for your contributions to this!
Rebased from previous PR #136.