1
<?php
2

3
namespace Nuwave\Lighthouse\Execution\Arguments;
4

5
use Nuwave\Lighthouse\Support\Contracts\ArgResolver;
6

7
class ResolveNested implements ArgResolver
8
{
9
    /**
10
     * @var callable|\Nuwave\Lighthouse\Support\Contracts\ArgResolver|null
11
     */
12
    protected $previous;
13

14
    /**
15
     * @var callable
16
     */
17
    protected $argPartitioner;
18

19
    /**
20
     * @param  callable|\Nuwave\Lighthouse\Support\Contracts\ArgResolver|null  $previous
21
     */
22 1
    public function __construct(callable $previous = null, callable $argPartitioner = null)
23
    {
24 1
        $this->previous = $previous;
25 1
        $this->argPartitioner = $argPartitioner ?? [ArgPartitioner::class, 'nestedArgResolvers'];
26
    }
27

28
    /**
29
     * @param  \Nuwave\Lighthouse\Execution\Arguments\ArgumentSet  $args
30
     */
31 1
    public function __invoke($root, $args)
32
    {
33 1
        [$nestedArgs, $regularArgs] = ($this->argPartitioner)($args, $root);
34

35 1
        if ($this->previous) {
36 1
            $root = ($this->previous)($root, $regularArgs);
37
        }
38

39
        /** @var \Nuwave\Lighthouse\Execution\Arguments\Argument $nested */
40 1
        foreach ($nestedArgs->arguments as $nested) {
41
            // @phpstan-ignore-next-line we know the resolver is there because we partitioned for it
42 1
            ($nested->resolver)($root, $nested->value);
43
        }
44

45 1
        return $root;
46
    }
47
}

Read our documentation on viewing source code .

Loading