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

api-platform / core / 14664641376

25 Apr 2025 12:30PM UTC coverage: 7.02%. First build
14664641376

Pull #6904

github

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

55 of 192 new or added lines in 9 files covered. (28.65%)

11165 of 159046 relevant lines covered (7.02%)

6.23 hits per line

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

26.67
/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\GraphQl\Subscription;
21
use ApiPlatform\Metadata\Operation;
22
use ApiPlatform\State\ProcessorInterface;
23

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

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

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

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

51
            $hub = \is_array($mercure) ? ($mercure['hub'] ?? null) : null;
×
52
            $data['mercureUrl'] = $this->mercureSubscriptionIriGenerator->generateMercureUrl($subscriptionId, $hub);
×
NEW
53
            if ($operation instanceof Subscription) {
×
NEW
54
                $data['isCollection'] = $operation->isCollection();
×
55
            }
56
        }
57

58
        return $data;
×
59
    }
60
}
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