axe/laravel-graphql-upload

GraphQL Upload middleware for Laravel and Lumen

v1.0.1 2018-09-24 15:46 UTC

This package is auto-updated.

Last update: 2024-04-25 05:59:01 UTC


README

GraphQL Upload middleware for Laravel and Lumen

This package is ported from https://github.com/Ecodev/graphql-upload

Install

composer require axe/laravel-graphql-upload

Usage

example use with Folklore\GraphQL

in the config/graphql file, use the middleware

    'middleware' => [
        Axe\LaravelGraphQLUpload\GraphqlUploadMiddleware::class
    ]

in your mutation:

<?php

namespace App\GraphQL\Mutation;

use Axe\LaravelGraphQLUpload\UploadType;
use Folklore\GraphQL\Support\Mutation;
use GraphQL;


class UploadFileMutation extends Mutation
{


    public function type()
    {
        return GraphQL::type('YourReturnType');
    }

    public function args()
    {
        return [
            "file" => ['name' => 'file', 'type' => UploadType::type()],
        ];
    }

    public function rules()
    {
        return [
            'file' => 'required|file|mimes:csv,txt',
        ];
    }

    public function resolve($root, $args)
    {
        $file = $args['file'];

        // call some function
        $path = $file->getRealPath();

        // ... your logic here
    }
}