You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.
You can do like this. paginateData, prepareRelations and prepareQuery are my custom functions inside this query class (actually, i wrote abstract class for query and my custom query class looks like setting some classnames into query variables, i can share it also)
The point is that in resolve() you should return an object with LengthAwarePaginator implemented.
<?php
declare(strict_types=1);
use App\GraphQL\Helpers\ResolveContext;
use Folklore\GraphQL\Support\Query;
use Folklore\GraphQL\Support\Traits\ShouldValidate;
use GraphQL;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
abstract class SomeQuery extends Query
{
use ShouldValidate;
public function type(): ObjectType
{
return GraphQL::pagination(GraphQL::type('SomeType'));
}
public function resolve(array $root, ?array $data, ResolveContext $context, ResolveInfo $resolveInfo): LengthAwarePaginator
{
$this->prepareRelations($resolveInfo);
if ($this->prepareQuery($data)) {
return $this->paginateData($context);
} else {
return new \Illuminate\Pagination\LengthAwarePaginator([], 0, $this->perPage);
}
}
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
How to paginate when using laravel-graphql?
The text was updated successfully, but these errors were encountered: