You are here

protected function QueryProcessor::doExecuteOperation in GraphQL 8.3

Parameters

\GraphQL\Executor\Promise\PromiseAdapter $adapter:

\GraphQL\Server\ServerConfig $config:

\GraphQL\Server\OperationParams $params:

\GraphQL\Language\AST\DocumentNode $document:

bool $validate:

Return value

\GraphQL\Executor\Promise\Promise

2 calls to QueryProcessor::doExecuteOperation()
QueryProcessor::executeCacheableOperation in src/GraphQL/Execution/QueryProcessor.php
QueryProcessor::executeUncachableOperation in src/GraphQL/Execution/QueryProcessor.php

File

src/GraphQL/Execution/QueryProcessor.php, line 284

Class

QueryProcessor

Namespace

Drupal\graphql\GraphQL\Execution

Code

protected function doExecuteOperation(PromiseAdapter $adapter, ServerConfig $config, OperationParams $params, DocumentNode $document, $validate = TRUE) {

  // If one of the validation rules found any problems, do not resolve the
  // query and bail out early instead.
  if ($validate && ($errors = $this
    ->validateOperation($config, $params, $document))) {
    return $adapter
      ->createFulfilled(new QueryResult(NULL, $errors));
  }
  $operation = $params->operation;
  $variables = $params->variables;
  $context = $this
    ->resolveContextValue($config, $params, $document, $operation);
  $root = $this
    ->resolveRootValue($config, $params, $document, $operation);
  $resolver = $config
    ->getFieldResolver();
  $schema = $config
    ->getSchema();
  $promise = Executor::promiseToExecute($adapter, $schema, $document, $root, $context, $variables, $operation, $resolver);
  return $promise
    ->then(function (ExecutionResult $result) use ($context) {
    $metadata = (new CacheableMetadata())
      ->addCacheContexts($context
      ->getCacheContexts())
      ->addCacheTags($context
      ->getCacheTags())
      ->setCacheMaxAge($context
      ->getCacheMaxAge());

    // Do not cache in development mode or if there are any errors.
    if ($context
      ->getGlobal('development') || !empty($result->errors)) {
      $metadata
        ->setCacheMaxAge(0);
    }
    return new QueryResult($result->data, $result->errors, $result->extensions, $metadata);
  });
}