You are here

class QueryConnection in GraphQL 8.4

Helper class that wraps entity queries.

Hierarchy

Expanded class hierarchy of QueryConnection

2 files declare their use of QueryConnection
ExampleSchema.php in examples/graphql_example/src/Plugin/GraphQL/Schema/ExampleSchema.php
QueryArticles.php in examples/graphql_example/src/Plugin/GraphQL/DataProducer/QueryArticles.php

File

examples/graphql_example/src/Wrappers/QueryConnection.php, line 11

Namespace

Drupal\graphql_examples\Wrappers
View source
class QueryConnection {

  /**
   * @var \Drupal\Core\Entity\Query\QueryInterface
   */
  protected $query;

  /**
   * QueryConnection constructor.
   *
   * @param \Drupal\Core\Entity\Query\QueryInterface $query
   */
  public function __construct(QueryInterface $query) {
    $this->query = $query;
  }

  /**
   * @return int
   */
  public function total() {
    $query = clone $this->query;
    $query
      ->range(NULL, NULL)
      ->count();
    return $query
      ->execute();
  }

  /**
   * @return array|\GraphQL\Deferred
   */
  public function items() {
    $result = $this->query
      ->execute();
    if (empty($result)) {
      return [];
    }
    $buffer = \Drupal::service('graphql.buffer.entity');
    $callback = $buffer
      ->add($this->query
      ->getEntityTypeId(), array_values($result));
    return new Deferred(function () use ($callback) {
      return $callback();
    });
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueryConnection::$query protected property
QueryConnection::items public function
QueryConnection::total public function
QueryConnection::__construct public function QueryConnection constructor.