class QueryConnection in GraphQL 8.4
Helper class that wraps entity queries.
Hierarchy
- class \Drupal\graphql_examples\Wrappers\QueryConnection
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\WrappersView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryConnection:: |
protected | property | ||
QueryConnection:: |
public | function | ||
QueryConnection:: |
public | function | ||
QueryConnection:: |
public | function | QueryConnection constructor. |