1
<?php
2

3
namespace Nuwave\Lighthouse\Schema\Directives;
4

5
use Closure;
6
use GraphQL\Type\Definition\ResolveInfo;
7
use Nuwave\Lighthouse\Schema\Values\FieldValue;
8
use Nuwave\Lighthouse\Support\Contracts\ArgDirective;
9
use Nuwave\Lighthouse\Support\Contracts\FieldMiddleware;
10
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
11

12
class RenameArgsDirective extends BaseDirective implements ArgDirective, FieldMiddleware
13
{
14 1
    public static function definition(): string
15
    {
16
        return /** @lang GraphQL */ <<<'GRAPHQL'
17 1
"""
18
Apply the @rename directives on the incoming arguments.
19
"""
20
directive @renameArgs on FIELD_DEFINITION
21
GRAPHQL;
22
    }
23

24 1
    public function handleField(FieldValue $fieldValue, Closure $next)
25
    {
26 1
        $resolver = $fieldValue->getResolver();
27

28 1
        return $next(
29 1
            $fieldValue->setResolver(
30
                function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver) {
31 1
                    $resolveInfo->argumentSet = $resolveInfo->argumentSet->rename();
32

33 1
                    return $resolver(
34 1
                        $root,
35 1
                        $resolveInfo->argumentSet->toArray(),
36
                        $context,
37
                        $resolveInfo
38
                    );
39
                }
40
            )
41
        );
42
    }
43
}

Read our documentation on viewing source code .

Loading