Пользовательская директива Laravel Lighthouse pass аргумент - PullRequest
0 голосов
/ 26 сентября 2019

Я использую Laravel + GraphQL + LightHouse.Я хочу передать аргумент пользовательской директиве.

мой schema.graphql ниже

type Query {
    rsv_holiday: [Rsv_holiday!]! @all
}

type Rsv_holiday {
    id: ID!
    holiday_type: Int!
    start_time: String!
    end_time: String!
    memo: String! @upperCase(key:"value")   // This is Custom Directive i declare.
}

UpperCaseDirective ниже (пользовательская директива)

<?php

namespace App\GraphQL\Directives;

use Closure;
use GraphQL\Type\Definition\ResolveInfo;
use Nuwave\Lighthouse\Schema\Values\FieldValue;
use Nuwave\Lighthouse\Support\Contracts\Directive;
use Nuwave\Lighthouse\Support\Contracts\FieldMiddleware;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;

class UpperCaseDirective  implements Directive, FieldMiddleware
{
    public function name(): string
    {
        return 'upperCase';
    }

    public function handleField(FieldValue $fieldValue, Closure $next): FieldValue
    {
        $previousResolver = $fieldValue->getResolver();

        $wrappedResolver = function ($root, array $args, GraphQLContext $context, ResolveInfo $info) use ($previousResolver): string {

            $result = $previousResolver($root, $args, $context, $info);
            // I want to do something with argument "value"
            return strtoupper($result);
        };

        $fieldValue->setResolver($wrappedResolver);
        return $next($fieldValue);
    }

}

Я хочу использовать«значение» в функции handleField.

Как я могу передать его?

...