You are here

protected function InternalRequest::resolveValues in GraphQL 8.3

Retrieve the list of field values.

Always returns a list of field values. Even for single value fields. Single/multi field handling is responsibility of the base class.

Parameters

mixed $value: The current object value.

array $args: Field arguments.

$context: The resolve context.

\GraphQL\Type\Definition\ResolveInfo $info: The resolve info object.

Return value

\Generator The value generator.

Overrides FieldPluginBase::resolveValues

File

modules/graphql_core/src/Plugin/GraphQL/Fields/Routing/InternalUrl/InternalRequest.php, line 97

Class

InternalRequest
Issue an internal request and retrieve the response object.

Namespace

Drupal\graphql_core\Plugin\GraphQL\Fields\Routing\InternalUrl

Code

protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
  if ($value instanceof Url) {
    $resolve = $this->subRequestBuffer
      ->add($value, function () {
      $request = $this->requestStack
        ->getCurrentRequest()
        ->duplicate();
      $request->attributes
        ->set('_controller', $request
        ->get('_graphql_controller'));
      $request->attributes
        ->remove('_graphql_subrequest');
      $request->attributes
        ->remove('_graphql_controller');
      $response = $this->httpKernel
        ->handle($request, HttpKernelInterface::SUB_REQUEST);

      // TODO:
      // Remove the request stack manipulation once the core issue described at
      // https://www.drupal.org/node/2613044 is resolved.
      while ($this->requestStack
        ->getCurrentRequest() === $request) {
        $this->requestStack
          ->pop();
      }
      return $response;
    });
    return function ($value, array $args, ResolveContext $context, ResolveInfo $info) use ($resolve) {

      /** @var \Drupal\graphql\GraphQL\Cache\CacheableValue $response */
      $response = $resolve();
      (yield new CacheableValue($response
        ->getValue(), [
        $response,
      ]));
    };
  }
}