• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/Metadata/Resource/Factory/LinkResourceMetadataCollectionFactory.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\Metadata\Resource\Factory;
15

16
use ApiPlatform\Metadata\Link;
17
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
18

19
/**
20
 * Prepares graphql links.
21
 *
22
 * @author Alan Poulain <contact@alanpoulain.eu>
23
 */
24
final class LinkResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
25
{
26
    public function __construct(private readonly LinkFactoryInterface $linkFactory, private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null, private bool $graphQlEnabled = false)
27
    {
28
    }
1,214✔
29

30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function create(string $resourceClass): ResourceMetadataCollection
34
    {
35
        $resourceMetadataCollection = new ResourceMetadataCollection($resourceClass);
101✔
36
        if ($this->decorated) {
101✔
37
            $resourceMetadataCollection = $this->decorated->create($resourceClass);
101✔
38
        }
39

40
        if (!$this->graphQlEnabled) {
101✔
41
            return $resourceMetadataCollection;
×
42
        }
43

44
        foreach ($resourceMetadataCollection as $i => $resource) {
101✔
45
            $graphQlOperations = [];
96✔
46
            foreach ($resource->getGraphQlOperations() ?? [] as $graphQlOperation) {
96✔
47
                $relationLinks = $this->linkFactory->createLinksFromRelations($graphQlOperation);
80✔
48
                $attributeLinks = $this->linkFactory->createLinksFromAttributes($graphQlOperation);
80✔
49
                $links = [];
80✔
50
                foreach ($attributeLinks as $link) {
80✔
UNCOV
51
                    $links[] = $this->linkFactory->completeLink($link);
1✔
52
                }
53
                $links = $this->mergeLinks($relationLinks, $links);
80✔
54

55
                $graphQlOperations[$graphQlOperation->getName()] = $graphQlOperation->withLinks($links);
80✔
56
            }
57

58
            $resource = $resource->withGraphQlOperations($graphQlOperations);
96✔
59
            $resourceMetadataCollection[$i] = $resource;
96✔
60
        }
61

62
        return $resourceMetadataCollection;
101✔
63
    }
64

65
    /**
66
     * @param Link[] $links
67
     * @param Link[] $toMergeLinks
68
     *
69
     * @return Link[]
70
     */
71
    private function mergeLinks(array $links, array $toMergeLinks): array
72
    {
73
        $classLinks = [];
80✔
74
        foreach ($links as $link) {
80✔
75
            $classLinks[$link->getToClass().'#'.$link->getFromProperty()] = $link;
22✔
76
        }
77

78
        foreach ($toMergeLinks as $link) {
80✔
UNCOV
79
            if (null !== $prevLink = $classLinks[$link->getToClass().'#'.$link->getFromProperty()] ?? null) {
1✔
UNCOV
80
                $classLinks[$link->getToClass().'#'.$link->getFromProperty()] = $prevLink->withLink($link);
1✔
81

UNCOV
82
                continue;
1✔
83
            }
84
            $classLinks[$link->getToClass().'#'.$link->getFromProperty()] = $link;
×
85
        }
86

87
        return array_values($classLinks);
80✔
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc