Lighthouse: @paginate causes default model detection to fail

Created on 5 Jan 2019  路  2Comments  路  Source: nuwave/lighthouse

Hi,
when try:
users: [User!]! @paginate @can(if:"view any user")

I have error:
No class 'UserPaginator' was found for directive 'can'

When I delete @can, query works fine. My @can directive is fine, works with other queries and mutations. I expect error when I don't have permissions, and paginated data when permissions is granted.

Schema

extend type Query {
    "Retrieve all users"
    users: [User!]! @paginate @can(if:"view any user")
}

Output/Logs

Click to expand

No class 'UserPaginator' was found for directive 'can'


Environment

Lighthouse Version: 2.6.3
Laravel Version: 5.7
PHP Version: 7.1.9

Additional context
I use https://github.com/spatie/laravel-permission to manage privileges.

bug

Most helpful comment

I avoid this issue by specifying model with v3.0-alpha.1.

extend type Query {
    "Retrieve all users"
    users: [User!]! @paginate @can(if:"view any user" model: "User")
}

All 2 comments

This happens because of the schema manipulation that @paginate does - when you look at the resulting user-facing schema, you will see the return type of the field gets renamed.

We have to adapt the logic of @can that guesses the Model name from the return type, probably by adding exceptions for the pagination suffixes ...Paginator and ...Connection. Preferrably integrated with the BaseDirective in a way that is reusable across mutliple directives.

I avoid this issue by specifying model with v3.0-alpha.1.

extend type Query {
    "Retrieve all users"
    users: [User!]! @paginate @can(if:"view any user" model: "User")
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Leuloch picture Leuloch  路  3Comments

caizhigang97 picture caizhigang97  路  3Comments

basudebpalfreelancer picture basudebpalfreelancer  路  4Comments

nguyentrongbang picture nguyentrongbang  路  3Comments

let-aurn picture let-aurn  路  3Comments