Uploading multiple files in Laravel Lighthouse GraphQL

First thing first, let me introduce myself. I am an experienced Software Engineer currently based in the UK. I am originally from Myanmar and I also used to work in Myanmar and Singapore as Full-Stack Software Engineer before I moved to the UK. If you want to reach me out, here is my LinkedIn profile, https://www.linkedin.com/in/wai-yan-hein-b99162123/.

This article will show you how to upload multiple files in GraphQL using Lighthouse library in Laravel. I assume you have basic knowledge about Laravel, GraphQL and Lighthouse PHP library.

This is the library we are using, https://lighthouse-php.com/. You will need to follow the installation guide on the documentation to integrate the library with the Laravel.

Let’s jump straight to the point and get our hands dirty. In order to upload multiple files, the first thing we have to do is declaring mutation in the schema as follow.

Take note that we import the `Upload` scalar type.

Then we will need to create a mutation for that running the following command.

php artisan lighthouse:mutation UploadFiles

Then, a mutation class will be created and we can implement the file upload logic there.

The following is the dummy code showing how to upload the files.

If you are writing tests, you can make the request as follow.

That’s it. That is how we upload multiple files in GraphQL for Laravel application. Hope this article is helpful.

Software Developer based in the UK, used to work in Singapore, but originally from Myanmar.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store