You are here

class QueryProvider in GraphQL 8.3

Hierarchy

Expanded class hierarchy of QueryProvider

1 string reference to 'QueryProvider'
graphql.services.yml in ./graphql.services.yml
graphql.services.yml
1 service uses QueryProvider
graphql.query_provider in ./graphql.services.yml
Drupal\graphql\GraphQL\QueryProvider\QueryProvider

File

src/GraphQL/QueryProvider/QueryProvider.php, line 7

Namespace

Drupal\graphql\GraphQL\QueryProvider
View source
class QueryProvider implements QueryProviderInterface {

  /**
   * Unsorted list of query providers nested and keyed by priority.
   *
   * @var \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface[]
   */
  protected $providers = [];

  /**
   * Sorted list of query providers.
   *
   * @var \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface[]
   */
  protected $sortedProviders;

  /**
   * {@inheritdoc}
   */
  public function getQuery($id, OperationParams $operation) {
    foreach ($this
      ->getSortedProviders() as $provider) {
      if ($query = $provider
        ->getQuery($id, $operation)) {
        return $query;
      }
    }
    return NULL;
  }

  /**
   * Adds a query provider.
   *
   * @param \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface $provider
   *   The query provider to add.
   * @param int $priority
   *   Priority of the query provider.
   */
  public function addQueryProvider(QueryProviderInterface $provider, $priority = 0) {
    $this->providers[$priority][] = $provider;
    $this->sortedProviders = NULL;
  }

  /**
   * Returns the sorted array of query providers.
   *
   * @return \Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface[]
   *   An array of query provider objects.
   */
  protected function getSortedProviders() {
    if (!isset($this->sortedProviders)) {
      krsort($this->providers);
      $this->sortedProviders = [];
      foreach ($this->providers as $providers) {
        $this->sortedProviders = array_merge($this->sortedProviders, $providers);
      }
    }
    return $this->sortedProviders;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueryProvider::$providers protected property Unsorted list of query providers nested and keyed by priority.
QueryProvider::$sortedProviders protected property Sorted list of query providers.
QueryProvider::addQueryProvider public function Adds a query provider.
QueryProvider::getQuery public function Returns a query string given the query parameters. Overrides QueryProviderInterface::getQuery
QueryProvider::getSortedProviders protected function Returns the sorted array of query providers.