我正在尝试获得在 Laravel Lighthouse GraphQL 中工作的 HasOne 关系。
它不起作用。突变不会给出错误,但也不会更新关系(员工 id 保持不变,而我希望它更改为 2):
mutation {
updateAccount(input: {
id: 12
employee: {
connect: 2
}
}) {
id
employee {
id
}
}
}
我的架构如下所示:
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
}
Account 和 Employee 模型如下所示:
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');
}
}
任何帮助或建议将不胜感激。
到目前为止,我已经尝试添加/删除@hasOne
或更改ID!
为[ID!]!
,但没有任何效果。