Search code examples
laravelgraphqllighthouselaravel-lighthouse

Laravel Lighthouse paginate field result


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.


Solution

  • 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.