Why is it that in the Lighthouse Docs, upload directive is listed and explained, but trying to use it in the schema:
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
}
returns:
"debugMessage": "No directive found for upload"
I later checked the changelog of Lighthouse, and found out that upload directive was added in v5.6.
Using
composer require nuwave/lighthouse
added v5.58 of Lighthouse instead, which is an unexpected behavior.
I finally used:
composer require nuwave/lighthouse dev-master
Which updated Lighthouse to the latest version v5.68+
Now, I got a new error:
"debugMessage": "Array to string conversion",
"message": "Internal server error"
I hope to find a way to upload files using upload directive soon.
==== SOLVED ====
Added json cast to image_path field, and wolla, it worked! It returned the following, with the 3 images uploaded, and the generated file names saved to database.
["images\/gallery\/LimSUx2xO9yvLYZg0Pl8L05MRcFISnLTprx1hOUq.jpg","images\/gallery\/3k8NSpOJFu6oYxplMW7Bik2j12mmVsHcOK1ZM4qJ.jpg","images\/gallery\/lRnpeAquOItYPZ35jPL2rBBDojWdxM2JkKosJ7Su.jpg"]
I am still testing the url of the uploaded image on the api:
localhost/images/gallery/LimSUx2xO9yvLYZg0Pl8L05MRcFISnLTprx1hOUq.jpg
Returns:
404 Not Found