Passed
Pull Request — main (#94)
by Tom
02:55
created

Driver::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
        return $this->get(Type\TypeManager::class)
25
            ->build(Type\Connection::class, $objectType->name . '_Connection', $objectType);
26
    }
27
28
    /**
29
     * Return a GraphQL type for the entity class
30
     *
31
     * @throws Error
32
     */
33
    public function type(string $entityClass): ObjectType
34
    {
35
        return $this->get(Metadata\Metadata::class)->get($entityClass)->getGraphQLType();
36
    }
37
38
    /**
39
     * Filters for a connection
40
     *
41
     * @throws Error
42
     */
43
    public function filter(string $entityClass): object
44
    {
45
        return $this->get(Criteria\CriteriaFactory::class)
46
            ->get($this->get(Metadata\Metadata::class)->get($entityClass));
47
    }
48
49
    /**
50
     * Pagination for a connection
51
     *
52
     * @throws Error
53
     */
54
    public function pagination(): object
55
    {
56
        return $this->get(TypeManager::class)->get('pagination');
57
    }
58
59
    /**
60
     * Resolve a connection
61
     *
62
     * @throws Error
63
     */
64
    public function resolve(string $entityClass, string $eventName = 'filter.querybuilder'): Closure
65
    {
66
        return $this->get(Resolve\ResolveEntityFactory::class)
67
            ->get($this->get(Metadata\Metadata::class)->get($entityClass), $eventName);
68
    }
69
70
    /**
71
     * @param string[] $requiredFields An optional list of just the required fields you want for the mutation.
72
     *                              This allows specific fields per mutation.
73
     * @param string[] $optionalFields An optional list of optional fields you want for the mutation.
74
     *                              This allows specific fields per mutation.
75
     */
76
    public function input(string $entityClass, array $requiredFields = [], array $optionalFields = []): InputObjectType
77
    {
78
        return $this->get(Input\InputFactory::class)->get($entityClass, $requiredFields, $optionalFields);
79
    }
80
}
81