spatie / fractalistic

A framework agnostic, developer friendly wrapper around Fractal
https://freek.dev/644-a-developer-friendly-wrapper-around-fractal
MIT License
382 stars 32 forks source link

Setting `withResourceName` results in an empty ParamBag for Includes. #49

Closed PeterCat12 closed 4 years ago

PeterCat12 commented 4 years ago

I'm not yet sure if this issue ultimately rests on Fractalistic or the underlying Fractal package. Will close if I determine this is the inappropriate place for this issue.

When \League\Fractal\TransformerAbstract::callIncludeMethod calls the \League\Fractal\Scope::getIdentifier method the resulting identifier is "incorrect" IF \Spatie\Fractalistic\Fractal::withResourceName was called to set a "top level identifier". It's "incorrect" in the sense that \League\Fractal\Manager::getIncludeParams method has no entry for the resulting identifier.

Code example:

url: /api/v1/abcd/users/36?include=comments:status_in(deleted)

... 
return fractal($user, $transformer, new JsonApiSerializer($base_url))
                ->withResourceName('abcd-users')
                ->respond($status, $headers);

Then in \League\Fractal\TransformerAbstract::callIncludeMethod

protected function callIncludeMethod(Scope $scope, $includeName, $data)
    {
        $scopeIdentifier = $scope->getIdentifier($includeName);
        // resulting `$scopeIdentifer` is `abcd-users.comments`
        $params = $scope->getManager()->getIncludeParams($scopeIdentifier);
        // `$params` is empty as the manager only has `includeParams` for `comments` (not `abcd-users.comments`).
       ... 
} 
PeterCat12 commented 4 years ago

https://github.com/thephpleague/fractal/issues/513 Will reopen if I determine the issue is with the fractal package.

spatie-bot commented 4 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.