I am trying to get a HasOne relation to work in Laravel Lighthouse GraphQL.
It doesn't work. The mutation does not give an error, but also doesn't update the relation (the employee id stays the same, while I want it to change to 2):
mutation {
updateAccount(input: {
id: 12
employee: {
connect: 2
}
}) {
id
employee {
id
}
}
}
My schema looks like this:
type Mutation {
updateAccount(input: UpdateAccount! @spread): Account! @update
}
input UpdateAccountInput {
id: ID!
employee: CreateEmployeeRelationInput @hasOne
}
input CreateEmployeeRelationInput {
connect: ID!
}
type Account {
id: ID!
...
employee: Employee! @hasOne
}
type Employee {
id: ID!
...
account: Account @belongsTo
}
The Account and Employee models looks like this:
class Account extends Model
{
public function employee(): HasOne
{
return $this->hasOne(\App\Models\Employee::class, 'account_id');
}
}
class Employee extends Model
{
public function account(): BelongsTo
{
return $this->belongsTo(\App\Models\Account::class, 'account_id');
}
}
Any help or suggestions would be appreciated.
So far I've tried to add/remove @hasOne
, or change ID!
to [ID!]!
, but nothing works.