1
<?php
2

3
namespace Nuwave\Lighthouse\Schema\Directives;
4

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

7
class BuilderDirective extends BaseDirective implements ArgBuilderDirective
8
{
9 1
    public static function definition(): string
10
    {
11
        return /** @lang GraphQL */ <<<'GRAPHQL'
12 1
"""
13
Use an argument to modify the query builder for a field.
14
"""
15
directive @builder(
16
  """
17
  Reference a method that is passed the query builder.
18
  Consists of two parts: a class name and a method name, separated by an `@` symbol.
19
  If you pass only a class name, the method name defaults to `__invoke`.
20
  """
21
  method: String!
22
) repeatable on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
23
GRAPHQL;
24
    }
25

26
    /**
27
     * Dynamically call a user-defined method to enhance the builder.
28
     *
29
     * @param  \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder  $builder
30
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
31
     */
32 1
    public function handleBuilder($builder, $value): object
33
    {
34 1
        $resolver = $this->getResolverFromArgument('method');
35

36 1
        return $resolver($builder, $value, $this->definitionNode);
37
    }
38
}

Read our documentation on viewing source code .

Loading