You are here

protected function Executor::doExecuteCached in GraphQL 8.4

Try to return cached results, otherwise resolve the query.

Parameters

string $prefix:

Return value

\GraphQL\Executor\Promise\Promise

1 call to Executor::doExecuteCached()
Executor::doExecute in src/GraphQL/Execution/Executor.php

File

src/GraphQL/Execution/Executor.php, line 239

Class

Executor
Executes GraphQL queries with cache lookup.

Namespace

Drupal\graphql\GraphQL\Execution

Code

protected function doExecuteCached($prefix) {
  if ($result = $this
    ->cacheRead($prefix)) {
    return $this->adapter
      ->createFulfilled($result);
  }
  return $this
    ->doExecuteUncached()
    ->then(function (ExecutionResult $result) use ($prefix) {
    if (!empty($result->errors)) {
      $this->context
        ->mergeCacheMaxAge(0);
    }
    $result = new CacheableExecutionResult($result->data, $result->errors, $result->extensions);
    $result
      ->addCacheableDependency($this->context);
    if ($result
      ->getCacheMaxAge() !== 0) {
      $this
        ->cacheWrite($prefix, $result);
    }
    return $result;
  });
}