突变nuwave/灯塔错误:^5.0和输入



我使用的是nuwave/b灯塔:^5.0,我正试图为一个具有belongsTo关系的实体创建一个突变。问题是,在我的输入中,我使用了一个消毒器指令来从字符串转换为id,但在那之后,当Laravel获得属性时,它会在类的验证中显示错误。此外,我调试了指令代码,它工作正常。

Error
"errors": [
{
"message": "The given data was invalid.",
"extensions": {
"validation": {
"content_type_id": [
"The content type id field is required."
]
},
"category": "validation"
},
Input 
input CreateContentInput {
content_type: CreateContentTypeBelongsTo!
.....
input CreateContentTypeBelongsTo {
connect: ID! @typeuuid(model: "App\ContentType")
create: CreateContentTypeInput
update: UpdateContentTypeInput
}
Model
class Content extends Model
{
protected $rules = [
'content_type_id' => 'required|integer|is_main_content_type',
];
/**
* @return BelongsTo
*/
public function contentType(): BelongsTo
{
return $this->belongsTo(ContentType::class);
}

任何想法都将受到的赞赏

几天后,我终于发现了这个问题。

错误来自主输入定义:

input CreateContentInput {
content_type: CreateContentTypeBelongsTo!
}

我遵循的是一个公司标准,即我们需要始终在**蛇的情况下使用这些属性**,尽管它们是关系。看起来Lighthouse总是用**骆驼式**来表示关系。

解决方案是将**重命名**属性添加到输入中。因此,正确的输入应该是:

input CreateContentInput {
content_type: CreateContentTypeBelongsTo! @rename (attribute: "contentType")
}

我希望这能帮助其他人。

最新更新