Laravel Lighthouse GraphQL数组到字符串错误

kqlmhetl  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(133)

为什么在Lighthouse Docs中列出并解释了upload指令,但试图在模式中使用它:

scalar Upload @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Upload")

extend type Mutation {
    createImageList(
        id: ID!
        category_id: String!
        image_path: [Upload!]! @upload(disk: "public", path: "images/gallery", public: true)
        thumbnail: String!
        label: String
        description: String
        tags: JSON
        favorite_count: Int
    ): GalleryImageList @upsert
}

退货:

"debugMessage": "No directive found for upload"

我后来检查了Lighthouse的修改日志,发现upload指令是在v5.6中添加的。使用composer require nuwave/lighthouse添加了Lighthouse的v5.58,这是一个意外的行为。
我终于习惯了:composer require nuwave/lighthouse dev-master哪个Lighthouse更新到了最新版本v5.68+
现在,我得到了一个新的错误:

"debugMessage": "Array to string conversion",
            "message": "Internal server error"

我希望很快找到一种使用upload指令上传文件的方法。

6fe3ivhb

6fe3ivhb1#

==== SOLVED =====添加json cast到image_path字段,哇,它成功了!它返回了以下内容,上传了3张图片,并将生成的文件名保存到数据库中。["images\/gallery\/LimSUx2xO9yvLYZg0Pl8L05MRcFISnLTprx1hOUq.jpg","images\/gallery\/3k8NSpOJFu6oYxplMW7Bik2j12mmVsHcOK1ZM4qJ.jpg","images\/gallery\/lRnpeAquOItYPZ35jPL2rBBDojWdxM2JkKosJ7Su.jpg"]
我仍在测试API上上传图像的url:
localhost/images/gallery/LimSUx2xO9yvLYZg0Pl8L05MRcFISnLTprx1hOUq.jpg
退货:404 Not Found

相关问题