【发布时间】:2022-12-12 14:03:11
【问题描述】:
为什么在 Lighthouse 文档中列出并解释了上传指令,但试图在模式中使用它:
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的changelog,发现在v5.6中增加了upload指令。
使用
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"
我希望尽快找到一种使用上传指令上传文件的方法。
【问题讨论】:
-
为此创建一个自定义突变
-
我已经尝试了自定义突变,并在模式中进行了导入:
scalar Upload @scalar(class: "App\\GraphQL\\Mutations\\Upload")但是 laravel 找不到该类。我如何让它发挥作用? -
现在,它可以看到类。我收到以下错误:
"message": "Variable \"$image_path\" got invalid value [{},{},{}]; Expected type Upload; Could not get uploaded file, be sure to conform to GraphQL multipart request specification: https:\/\/github.com\/jaydenseric\/graphql-multipart-request-spec Instead got: [{},{},{}]",这与我从[Upload!]! to Upload!更改字段类型时遇到的错误相同 -
更新我发现使用字段类型:
[Upload!]!确实有效,因为图像已上传到公共驱动器中指定的文件夹,尽管它仍然给出以下错误,并且数据库未按照突变中所述更新:@ 987654330@ -
我相信你不应该使用
[Upload!]!,而应该只使用Upload!。
标签: laravel graphql laravel-lighthouse