-
Notifications
You must be signed in to change notification settings - Fork 66
Closed
Labels
Description
At the application level a developer is presented with the request that might look like this:
GET /sites/1?include=posts.comments,comments.author&fields[comments]=body HTTP/1.1
Accept: application/vnd.api+json
From the test example EncodeIncludedObjectsTest we can see that the include
and fields
parameters need to be combined (in this example comments
):
public function testEncodeWithRecursiveIncludedObjects()
{
$this->author->{Author::LINK_COMMENTS} = $this->comments;
$actual = Encoder::instance([
Author::class => AuthorSchema::class,
Comment::class => CommentSchema::class,
Post::class => PostSchema::class,
Site::class => SiteSchema::class,
], $this->encoderOptions)->encodeData($this->site, new EncodingParameters(
// include only this relation (according to the spec intermediate will be included as well)
[Site::LINK_POSTS . '.' . Post::LINK_COMMENTS],
// include only these attributes and links
[
'comments' => [Comment::ATTRIBUTE_BODY, Comment::LINK_AUTHOR],
'posts' => [Post::LINK_COMMENTS],
'sites' => [Site::LINK_POSTS],
]
));
:
:
}
Given that the url will contain the includes and fields in separate parameters, it is up to the application level to correctly parse posts.comments,comments.author
and figure out to create the following for the $includePaths
:
[Site::LINK_POSTS . '.' . Post::LINK_COMMENTS], // posts.comments
and
'comments' => [Comment::ATTRIBUTE_BODY, Comment::LINK_AUTHOR /*author*/],
for $fieldSets
.
Would it not be better to put this logic in the library?