|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApiSkeletons\Doctrine\GraphQL; |
|
6
|
|
|
|
|
7
|
|
|
use ApiSkeletons\Doctrine\GraphQL\Type\TypeManager; |
|
8
|
|
|
use Closure; |
|
9
|
|
|
use GraphQL\Error\Error; |
|
10
|
|
|
use GraphQL\Type\Definition\InputObjectType; |
|
11
|
|
|
use GraphQL\Type\Definition\ObjectType; |
|
12
|
|
|
|
|
13
|
|
|
class Driver extends AbstractContainer |
|
14
|
|
|
{ |
|
15
|
|
|
use Services; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Return a connection wrapper for a type |
|
19
|
|
|
* |
|
20
|
|
|
* @throws Error |
|
21
|
|
|
*/ |
|
22
|
|
|
public function connection(ObjectType $objectType): ObjectType |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Connections rely on the entity ObjectType so the build() method is used |
|
26
|
|
|
*/ |
|
27
|
|
|
return $this->get(Type\TypeManager::class) |
|
28
|
|
|
->build(Type\Connection::class, $objectType->name . '_Connection', $objectType); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Return a GraphQL type for the entity class |
|
33
|
|
|
* |
|
34
|
|
|
* @throws Error |
|
35
|
|
|
*/ |
|
36
|
|
|
public function type(string $entityClass): ObjectType |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->get(Type\TypeManager::class)->build(Type\Entity::class, $entityClass)(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Filters for a connection |
|
43
|
|
|
* |
|
44
|
|
|
* @throws Error |
|
45
|
|
|
*/ |
|
46
|
|
|
public function filter(string $entityClass): object |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->get(Criteria\CriteriaFactory::class)->get( |
|
49
|
|
|
$this->get(Type\TypeManager::class) |
|
50
|
|
|
->build(Type\Entity::class, $entityClass), |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Pagination for a connection |
|
56
|
|
|
* |
|
57
|
|
|
* @throws Error |
|
58
|
|
|
*/ |
|
59
|
|
|
public function pagination(): object |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->get(TypeManager::class)->get('pagination'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Resolve a connection |
|
66
|
|
|
* |
|
67
|
|
|
* @throws Error |
|
68
|
|
|
*/ |
|
69
|
|
|
public function resolve(string $entityClass, string $eventName = 'filter.querybuilder'): Closure |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->get(Resolve\ResolveEntityFactory::class)->get( |
|
72
|
|
|
$this->get(Type\TypeManager::class) |
|
73
|
|
|
->build(Type\Entity::class, $entityClass), |
|
74
|
|
|
$eventName, |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string[] $requiredFields An optional list of just the required fields you want for the mutation. |
|
80
|
|
|
* This allows specific fields per mutation. |
|
81
|
|
|
* @param string[] $optionalFields An optional list of optional fields you want for the mutation. |
|
82
|
|
|
* This allows specific fields per mutation. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function input(string $entityClass, array $requiredFields = [], array $optionalFields = []): InputObjectType |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->get(Input\InputFactory::class)->get($entityClass, $requiredFields, $optionalFields); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|