This repository has been archived by the owner on Mar 29, 2020. It is now read-only.
Default resolver for connections
Pre-release
Pre-release
If no resolve method is set on a connection, the following function will be used:
function ($collection, array $args, ResolveInfo $info) use ($name) {
$items = [];
if ($collection instanceof Model) {
$items = $collection->getAttribute($name);
} else if (is_object($collection) && method_exists($collection, 'get')) {
$items = $collection->get($name);
} else if (is_array($collection) && isset($collection[$name])) {
$items = new Collection($collection[$name]);
}
if (isset($args['first'])) {
$total = $items->count();
$first = $args['first'];
$after = $this->decodeCursor($args);
$currentPage = $first && $after ? floor(($first + $after) / $first) : 1;
return new Paginator(
$items->slice($after)->take($first),
$total,
$first,
$currentPage
);
}
return new Paginator(
$items,
count($items),
count($items)
);
}