Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
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 .