You are here

protected function RequestController::handleBatch in GraphQL 8.4

Same name and namespace in other branches
  1. 8.3 src/Controller/RequestController.php \Drupal\graphql\Controller\RequestController::handleBatch()

Execute multiple operations as batch and turn that into cacheable response.

Parameters

\Drupal\graphql\Entity\ServerInterface $server:

\GraphQL\Server\OperationParams[] $operations:

Return value

\Drupal\Core\Cache\CacheableJsonResponse

Throws

\Exception

1 call to RequestController::handleBatch()
RequestController::handleRequest in src/Controller/RequestController.php
Handles graphql requests.

File

src/Controller/RequestController.php, line 93

Class

RequestController
The main GraphQL request handler that will forward to the responsible server.

Namespace

Drupal\graphql\Controller

Code

protected function handleBatch(ServerInterface $server, array $operations) {
  $result = $server
    ->executeBatch($operations);
  $response = new CacheableJsonResponse($result);

  // In case of a batch request, the result is an array.
  foreach ($result as $dependency) {
    $response
      ->addCacheableDependency($dependency);
  }
  return $response;
}