Passed
Pull Request — master (#2445)
by
unknown
03:49
created

GraphQlQueryResolverPass::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 1
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 ApiPlatform\Core\Exception\RuntimeException;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * Injects GraphQL resolvers.
23
 *
24
 * @internal
25
 *
26
 * @author Lukas Lücke <[email protected]>
27
 */
28
final class GraphQlQueryResolverPass implements CompilerPassInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function process(ContainerBuilder $container)
34
    {
35
        $resolvers = [];
36
        foreach ($container->findTaggedServiceIds('api_platform.graphql.query_resolver', true) as $serviceId => $tags) {
37
            foreach ($tags as $tag) {
38
                if (!isset($tag['id'])) {
39
                    $tag['id'] = $serviceId;
40
                }
41
42
                $resolvers[$tag['id']] = new Reference($serviceId);
43
            }
44
        }
45
46
        $container->getDefinition('api_platform.graphql.query_resolver_locator')->addArgument($resolvers);
47
    }
48
}
49