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