You are here

public function SubrequestExtractionController::extract in GraphQL 8.3

Same name and namespace in other branches
  1. 8.4 src/Controller/SubrequestExtractionController.php \Drupal\graphql\Controller\SubrequestExtractionController::extract()

Extracts the sub-request callback response.

Return value

\Drupal\graphql\GraphQL\Buffers\SubRequestResponse The sub-request response object.

File

src/Controller/SubrequestExtractionController.php, line 65

Class

SubrequestExtractionController
Extract arbitrary information from subrequests.

Namespace

Drupal\graphql\Controller

Code

public function extract() {
  $request = $this->requestStack
    ->getCurrentRequest();
  $callback = $request->attributes
    ->get('_graphql_subrequest');

  // TODO: Remove this once https://www.drupal.org/project/drupal/issues/2940036#comment-12479912 is resolved.
  $this->languageManager
    ->reset();

  // Collect any potentially leaked cache metadata released by the callback.
  $context = new RenderContext();
  $result = $this->renderer
    ->executeInRenderContext($context, function () use ($callback) {
    return $callback();
  });
  $response = new SubRequestResponse($result);
  if (!$context
    ->isEmpty()) {
    $response
      ->addCacheableDependency($context
      ->pop());
  }
  return $response;
}