QueryConnection.php in GraphQL 8.4
File
examples/graphql_example/src/Wrappers/QueryConnection.php
View source
<?php
namespace Drupal\graphql_examples\Wrappers;
use Drupal\Core\Entity\Query\QueryInterface;
use GraphQL\Deferred;
class QueryConnection {
protected $query;
public function __construct(QueryInterface $query) {
$this->query = $query;
}
public function total() {
$query = clone $this->query;
$query
->range(NULL, NULL)
->count();
return $query
->execute();
}
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();
});
}
}