Passed
Push — main ( 4eb27b...5a3b3e )
by Tom
03:14 queued 29s
created

Driver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 4
rs 10
c 1
b 0
f 0
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