|
7 | 7 | use Doctrine\ORM\Mapping\ClassMetadata; |
8 | 8 | use Doctrine\ORM\QueryBuilder; |
9 | 9 | use GraphQL\Doctrine\Factory\UniqueNameFactory; |
10 | | -use GraphQL\Doctrine\Types; |
11 | 10 | use GraphQL\Type\Definition\LeafType; |
12 | | -use GraphQL\Type\Definition\Type; |
13 | 11 |
|
14 | | -final class EmptyOperatorType extends AbstractOperator |
| 12 | +final class EmptyOperatorType extends AbstractAssociationOperatorType |
15 | 13 | { |
16 | | - protected function getConfiguration(Types $types, LeafType $leafType): array |
| 14 | + protected function getConfiguration(LeafType $leafType): array |
17 | 15 | { |
18 | 16 | return [ |
| 17 | + 'description' => 'When used on single valued association, it will use `IS NULL` operator. On collection valued association it will use `IS EMPTY` operator.', |
19 | 18 | 'fields' => [ |
20 | 19 | [ |
21 | 20 | 'name' => 'not', |
22 | | - 'type' => Type::boolean(), |
| 21 | + 'type' => self::boolean(), |
23 | 22 | 'defaultValue' => false, |
24 | 23 | ], |
25 | 24 | ], |
26 | 25 | ]; |
27 | 26 | } |
28 | 27 |
|
29 | | - public function getDqlCondition(UniqueNameFactory $uniqueNameFactory, ClassMetadata $metadata, QueryBuilder $queryBuilder, string $alias, string $field, ?array $args): ?string |
| 28 | + protected function getSingleValuedDqlCondition(UniqueNameFactory $uniqueNameFactory, ClassMetadata $metadata, QueryBuilder $queryBuilder, string $alias, string $field, array $args): ?string |
30 | 29 | { |
31 | | - if ($args === null) { |
32 | | - return null; |
33 | | - } |
| 30 | + $null = $this->types->getOperator(NullOperatorType::class, self::id()); |
34 | 31 |
|
| 32 | + return $null->getDqlCondition($uniqueNameFactory, $metadata, $queryBuilder, $alias, $field, $args); |
| 33 | + } |
| 34 | + |
| 35 | + protected function getCollectionValuedDqlCondition(UniqueNameFactory $uniqueNameFactory, ClassMetadata $metadata, QueryBuilder $queryBuilder, string $alias, string $field, array $args): ?string |
| 36 | + { |
35 | 37 | $not = $args['not'] ? 'NOT ' : ''; |
36 | 38 |
|
37 | 39 | return $alias . '.' . $field . ' IS ' . $not . 'EMPTY'; |
|
0 commit comments