protected function buildWrappedResponse(TopLevelDataInterface
$data, Request
$request, IncludedData
$includes,
$response_code = 200, array
$headers =
[], LinkCollection
$links = NULL, array
$meta =
[]) { $links =
($links ?:
new LinkCollection([]));
if (!
$links->
hasLinkWithKey('self'
)) { $self_link =
new Link(new CacheableMetadata(), self::
getRequestLink($request), 'self'
);
$links =
$links->
withLink('self',
$self_link);
} $document =
new JsonApiDocumentTopLevel($data,
$includes,
$links,
$meta);
if (!
$request->
isMethodCacheable()) { return new ResourceResponse($document,
$response_code,
$headers);
} $response =
new CacheableResourceResponse($document,
$response_code,
$headers);
$cacheability =
(new CacheableMetadata())->
addCacheContexts([ // Make sure that different sparse fieldsets are cached differently.
'url.query_args:fields',
// Make sure that different sets of includes are cached differently.