1
<?php
2

3
namespace Nuwave\Lighthouse\WhereConditions;
4

5
class WhereConditionsDirective extends WhereConditionsBaseDirective
6
{
7 0
    public static function definition(): string
8
    {
9
        return /** @lang GraphQL */ <<<'GRAPHQL'
10 0
"""
11
Add a dynamically client-controlled WHERE condition to a fields query.
12
"""
13
directive @whereConditions(
14
    """
15
    Restrict the allowed column names to a well-defined list.
16
    This improves introspection capabilities and security.
17
    Mutually exclusive with the `columnsEnum` argument.
18
    """
19
    columns: [String!]
20

21
    """
22
    Use an existing enumeration type to restrict the allowed columns to a predefined list.
23
    This allowes you to re-use the same enum for multiple fields.
24
    Mutually exclusive with the `columns` argument.
25
    """
26
    columnsEnum: String
27
) on ARGUMENT_DEFINITION
28
GRAPHQL;
29
    }
30

31
    /**
32
     * @param  \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder  $builder
33
     * @param  array<string, mixed>|null  $whereConditions
34
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
35
     */
36 1
    public function handleBuilder($builder, $whereConditions): object
37
    {
38
        // The value `null` should be allowed but have no effect on the query.
39 1
        if (is_null($whereConditions)) {
40 1
            return $builder;
41
        }
42

43 1
        return $this->handleWhereConditions($builder, $whereConditions);
44
    }
45

46 1
    protected function generatedInputSuffix(): string
47
    {
48 1
        return 'WhereConditions';
49
    }
50
}

Read our documentation on viewing source code .

Loading