-
-
Notifications
You must be signed in to change notification settings - Fork 466
Closed as not planned
Labels
needs reproductionFailing test case neededFailing test case needed
Description
Describe the bug
When using @whereAuth directive to filter models owned by the user, if the model has a pivot table the directive doesn't return it.
This is the query i'm using, every pivot is returning null.
{
commissionsUser (first: 10) {
data {
id
pivot {
id
}
}
}
}
Expected behavior/Solution
Lighthouse should return the pivot table of the relationship when using the @whereAuth directive if it has a pivot.
Steps to reproduce
Here is the schema:
type CommissionUserPivot {
id: ID!
commission_value: Float
confirmed_at: Boolean
was_quantity_changed: Boolean
user: User @belongsTo
role: Role @belongsTo
}
type Commission {
id: ID!
pivot: CommissionUserPivot
}
The relationship method on User class:
public function commissions()
{
return $this->belongsToMany(Commission::class)
->using(CommissionUser::class)
->withPivot([
'id',
'commission_value',
'confirmed_at',
'was_quantity_changed',
'role_id'
]);
}
Also i made the same relationship on Commission class to be sure:
public function users()
{
return $this->belongsToMany(User::class)
->using(CommissionUser::class)
->withPivot([
'id',
'commission_value',
'confirmed_at',
'was_quantity_changed',
'role_id'
]);
}
If i use the directive every pivot is returned null, for example:
extend type Query {
commissionsUser: [Commission] @paginate @whereAuth(relation: "users")
}
{
"data": {
"commissionsUser": {
"data": [
{
"id": "33",
"pivot": null
},
{
"id": "34",
"pivot": null
}
]
}
}
}
But if i use a custom builder, every pivot is returned as intended:
extend type Query {
commissionsUser: [Commission] @paginate(builder: "\\App\\GraphQL\\Builders\\CommissionsUserBuilder")
}
class CommissionsUserBuilder
{
public function __invoke()
{
return Auth::user()->commissions();
}
}
{
"data": {
"commissionsUser": {
"data": [
{
"id": "33",
"pivot": {
"id": "1"
}
},
{
"id": "34",
"pivot": {
"id": "2"
}
}
]
}
}
}
Lighthouse Version
5.39
Metadata
Metadata
Assignees
Labels
needs reproductionFailing test case neededFailing test case needed