Completed
Pull Request — 2.4 (#2992)
by Vincent
06:43
created

GraphQlQueryResolverPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 4
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
/**
21
 * Injects GraphQL resolvers.
22
 *
23
 * @internal
24
 *
25
 * @author Lukas Lücke <[email protected]>
26
 */
27
final class GraphQlQueryResolverPass implements CompilerPassInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function process(ContainerBuilder $container)
33
    {
34
        if (!$container->getParameter('api_platform.graphql.enabled')) {
35
            return;
36
        }
37
38
        $resolvers = [];
39
        foreach ($container->findTaggedServiceIds('api_platform.graphql.query_resolver', true) as $serviceId => $tags) {
40
            foreach ($tags as $tag) {
41
                $resolvers[$tag['id'] ?? $serviceId] = new Reference($serviceId);
42
            }
43
        }
44
45
        $container->getDefinition('api_platform.graphql.query_resolver_locator')->addArgument($resolvers);
46
    }
47
}
48