axe/laravel-graphql-upload

GraphQL Upload middleware for Laravel and Lumen
1,151
Install
composer require axe/laravel-graphql-upload
Latest Version:v1.0.1
PHP:>=7.1.0
License:MIT
Last Updated:Sep 24, 2018
Links: GitHub  ·  Packagist
Maintainer: axe

laravel-graphql-upload

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
    }
}