• 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

84.62
/src/GraphQl/State/Processor/SubscriptionProcessor.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\GraphQl\State\Processor;
15

16
use ApiPlatform\GraphQl\Subscription\MercureSubscriptionIriGeneratorInterface;
17
use ApiPlatform\GraphQl\Subscription\OperationAwareSubscriptionManagerInterface;
18
use ApiPlatform\GraphQl\Subscription\SubscriptionManagerInterface;
19
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\State\ProcessorInterface;
22

23
/**
24
 * Adds the mercure subscription url if available.
25
 */
26
final class SubscriptionProcessor implements ProcessorInterface
27
{
28
    public function __construct(private readonly ProcessorInterface $decorated, private readonly SubscriptionManagerInterface $subscriptionManager, private readonly ?MercureSubscriptionIriGeneratorInterface $mercureSubscriptionIriGenerator)
29
    {
30
    }
161✔
31

32
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
33
    {
34
        $data = $this->decorated->process($data, $operation, $uriVariables, $context);
120✔
35
        if (!$operation instanceof GraphQlOperation || !($mercure = $operation->getMercure())) {
120✔
36
            return $data;
119✔
37
        }
38

UNCOV
39
        if ($this->subscriptionManager instanceof OperationAwareSubscriptionManagerInterface) {
1✔
UNCOV
40
            $subscriptionId = $this->subscriptionManager->retrieveSubscriptionId($context, $data, $operation);
1✔
41
        } else {
42
            $subscriptionId = $this->subscriptionManager->retrieveSubscriptionId($context, $data);
×
43
        }
44

UNCOV
45
        if ($subscriptionId) {
1✔
UNCOV
46
            if (!$this->mercureSubscriptionIriGenerator) {
1✔
47
                throw new \LogicException('Cannot use Mercure for subscriptions when MercureBundle is not installed. Try running "composer require mercure".');
×
48
            }
49

UNCOV
50
            $hub = \is_array($mercure) ? ($mercure['hub'] ?? null) : null;
1✔
UNCOV
51
            $data['mercureUrl'] = $this->mercureSubscriptionIriGenerator->generateMercureUrl($subscriptionId, $hub);
1✔
52
        }
53

UNCOV
54
        return $data;
1✔
55
    }
56
}
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