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 Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective; |
|
6 |
|
|
7 |
class InDirective extends BaseDirective implements ArgBuilderDirective |
|
8 |
{
|
|
9 | 1 |
public static function definition(): string |
10 |
{
|
|
11 |
return /** @lang GraphQL */ <<<'GRAPHQL' |
|
12 | 1 |
"""
|
13 |
Use the client given list value to add an IN conditional to a database query.
|
|
14 |
"""
|
|
15 |
directive @in(
|
|
16 |
"""
|
|
17 |
Specify the database column to compare.
|
|
18 |
Only required if database column has a different name than the attribute in your schema.
|
|
19 |
"""
|
|
20 |
key: String
|
|
21 |
) repeatable on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
|
|
22 |
GRAPHQL; |
|
23 |
}
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Apply a simple "WHERE IN $values" clause.
|
|
27 |
*
|
|
28 |
* @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
|
|
29 |
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
|
|
30 |
*/
|
|
31 | 1 |
public function handleBuilder($builder, $values): object |
32 |
{
|
|
33 | 1 |
return $builder->whereIn( |
34 | 1 |
$this->directiveArgValue('key', $this->nodeName()), |
35 |
$values
|
|
36 |
);
|
|
37 |
}
|
|
38 |
}
|
Read our documentation on viewing source code .