jsonapi-bundle icon indicating copy to clipboard operation
jsonapi-bundle copied to clipboard

Bundle doesn't work with batch/subrequests

Open sboesch opened this issue 5 years ago • 0 comments

We wanted to create a /batch route by using the HttpKernel:

foreach($requests as $request) {
    // ...
    $req = Request::create(
        $request['relative_url'],
        $request['method'],
        $options
    );
    $response = $kernel->handle($req);
}

However, since the ResourceCollection service (and probably others like JsonApi) sets the request on construction, it doesn't work with follow up requests:

/**
 * ResourceCollection constructor.
 */
public function __construct(RequestStack $requestStack, FinderCollection $finderCollection, Paginator $paginator, FieldManager $fieldManager)
{
    $this->request = $requestStack->getCurrentRequest();
    // ...
}

It will handle the same request over and over again.

sboesch avatar Mar 31 '20 13:03 sboesch