I have a query on Lighthouse which is using @paginate
scope with another 3 scopes
This is my query
profiles(where: _ @whereConditions(columns: ["email"])): [User!]! @paginate(scopes: ["byOrganizationLoggedIn","byMatchingRole", "byAvailableMatching"]) @middleware(checks: ["auth:api"])
And those are my scopes from User entity.
/**
* @param [type] $query
*/
public function scopeByOrganizationLoggedIn($query)
{
if ($organization = request()->user()->organization_id) {
$query->where('organization_id', $organization);
}
}
/**
* @param [type] $query
*/
public function scopeByMatchingRole(Builder $query)
{
if (request()->user()) {
$query->whereHas('roles', function ($q) {
$q->whereIn('name', ['Mentor', 'Mentee']);
});
}
}
/**
* @param [type] $query
*/
public function scopeByAvailableMatching(Builder $query)
{
if (request()->user()) {
$query->whereDoesntHave('matchedProfiles', function (Builder $q) {
$q->where('user_id', request()->user()->id);
});
}
}
The problem is that my last scope byAvailableMatching
is not called and if I remove one of the other scopes byOrganizationLoggedIn
or byMatchingRole
it's still going into the entity methods.
I've tried to reset the lighthouse cache using
php artisan lighthouse:clear-cache
But the query and the scopes are not updated and they are returning the same data.
I'm new to Laravel and Lighthouse and if you have any suggestions to filter the query by all the scopes let me know.