Laravel Lighthouse paginate field result

Viewed 1332

I have defined a query in lighthouse:

extend type Query {
    products(input: ListInput @spread): [Product]
        @field(resolver: "App\\GraphQL\\Queries\\BusinessInformation\\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.

2 Answers

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\\CustomerManagement\\TariffBook\\ProductComplex@index")
}

Just nedded to use builder inside paginate directive.

Related