You are here

protected function QueryProcessor::cacheIdentifier in GraphQL 8.3

Parameters

\GraphQL\Server\OperationParams $params:

\GraphQL\Language\AST\DocumentNode $document:

array $contexts:

Return value

string

1 call to QueryProcessor::cacheIdentifier()
QueryProcessor::executeCacheableOperation in src/GraphQL/Execution/QueryProcessor.php

File

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

Class

QueryProcessor

Namespace

Drupal\graphql\GraphQL\Execution

Code

protected function cacheIdentifier(OperationParams $params, DocumentNode $document, array $contexts = []) {

  // Ignore language contexts since they are handled by graphql internally.
  $contexts = $contexts;
  $keys = $this->contextsManager
    ->convertTokensToKeys($contexts)
    ->getKeys();

  // Sorting the variables will cause fewer cache vectors.
  $variables = $params->variables ?: [];
  ksort($variables);

  // Prepend the hash of the serialized document to the cache contexts.
  $hash = hash('sha256', json_encode([
    'query' => $this
      ->serializeDocument($document),
    'variables' => $variables,
  ]));
  return implode(':', array_values(array_merge([
    $hash,
  ], $keys)));
}