2

I have defined a query in lighthouse:

extend type Query {
    products(input: ListInput @spread): [Product]
        @field(resolver: "App\\GraphQL\\Queries\\ProductComplex@index")
}

but the result of products is not paginated. I can not use both @field and @paginate at the same time because there should be only one resolver. How can I paginate an eloquent query with custom resolver?

I've searched and found that I builder could be used but I don't want to use query builders when I have defined the appropriate model.

Alireza A2F
  • 519
  • 4
  • 26
  • Have you managed to solve this? If you did, do you mind answering the question yourself? I am struggling with the exact same thing. – user3454396 Jun 26 '20 at 16:26

2 Answers2

3

I managed to find the solution:

extend type Query {
    products(captionId: ID, subFieldId: ID, q: String): [Product]
    @paginate(type: "paginator" defaultCount: 10 maxCount: 100
        builder: "App\\GraphQL\\Queries\\ProductComplex@index")
}

Just nedded to use builder inside paginate directive.

Alireza A2F
  • 519
  • 4
  • 26
0

Just add pagination to your query $posts = DB::table('posts')->paginate(12);

Also, here you will found several solutions to this problem: How to use pagination with laravel DB::select query

Cheer.

Cristian
  • 348
  • 2
  • 14