You are here

public function EntityQueryMapQueryProvider::getQuery in GraphQL 8.3

Returns a query string given the query parameters.

Can be used to load a query string from arbitrary query parameters e.g. when using persisted queries (loading queries by their hash or version and id).

Parameters

string $id: The query id.

\GraphQL\Server\OperationParams $operation: The operation parameters.

Return value

string|null The query string or NULL if it couldn't be determined.

Overrides QueryProviderInterface::getQuery

File

src/GraphQL/QueryProvider/EntityQueryMapQueryProvider.php, line 30

Class

EntityQueryMapQueryProvider

Namespace

Drupal\graphql\GraphQL\QueryProvider

Code

public function getQuery($id, OperationParams $operation) {
  list($version, $id) = explode(':', $id);

  // Check that the id is properly formatted.
  if (empty($version) || empty($id)) {
    return NULL;
  }
  $storage = $this->entityTypeManager
    ->getStorage('graphql_query_map');

  /** @var \Drupal\graphql\Entity\QueryMapInterface $map */
  if ($map = $storage
    ->load($version)) {
    return $map
      ->getQuery($id);
  }
  return NULL;
}