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

api-platform / core / 6067528200

04 Sep 2023 12:12AM UTC coverage: 36.875% (-21.9%) from 58.794%
6067528200

Pull #5791

github

web-flow
Merge 64157e578 into d09cfc9d2
Pull Request #5791: fix: strip down any sql function name

3096 of 3096 new or added lines in 205 files covered. (100.0%)

9926 of 26918 relevant lines covered (36.87%)

6.5 hits per line

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

0.0
/src/GraphQl/Resolver/Factory/ItemSubscriptionResolverFactory.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\Resolver\Factory;
15

16
use ApiPlatform\GraphQl\Resolver\Stage\ReadStageInterface;
17
use ApiPlatform\GraphQl\Resolver\Stage\SecurityStageInterface;
18
use ApiPlatform\GraphQl\Resolver\Stage\SerializeStageInterface;
19
use ApiPlatform\GraphQl\Subscription\MercureSubscriptionIriGeneratorInterface;
20
use ApiPlatform\GraphQl\Subscription\SubscriptionManagerInterface;
21
use ApiPlatform\Metadata\GraphQl\Operation;
22
use ApiPlatform\Metadata\Util\ClassInfoTrait;
23
use ApiPlatform\Metadata\Util\CloneTrait;
24
use GraphQL\Type\Definition\ResolveInfo;
25

26
/**
27
 * Creates a function resolving a GraphQL subscription of an item.
28
 *
29
 * @author Alan Poulain <contact@alanpoulain.eu>
30
 */
31
final class ItemSubscriptionResolverFactory implements ResolverFactoryInterface
32
{
33
    use ClassInfoTrait;
34
    use CloneTrait;
35

36
    public function __construct(private readonly ReadStageInterface $readStage, private readonly SecurityStageInterface $securityStage, private readonly SerializeStageInterface $serializeStage, private readonly SubscriptionManagerInterface $subscriptionManager, private readonly ?MercureSubscriptionIriGeneratorInterface $mercureSubscriptionIriGenerator)
37
    {
38
    }
×
39

40
    public function __invoke(string $resourceClass = null, string $rootClass = null, Operation $operation = null): callable
41
    {
42
        return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation): ?array {
×
43
            if (null === $resourceClass || null === $operation) {
×
44
                return null;
×
45
            }
46

47
            $resolverContext = ['source' => $source, 'args' => $args, 'info' => $info, 'is_collection' => false, 'is_mutation' => false, 'is_subscription' => true];
×
48

49
            $item = ($this->readStage)($resourceClass, $rootClass, $operation, $resolverContext);
×
50
            if (null !== $item && !\is_object($item)) {
×
51
                throw new \LogicException('Item from read stage should be a nullable object.');
×
52
            }
53
            ($this->securityStage)($resourceClass, $operation, $resolverContext + [
×
54
                'extra_variables' => [
×
55
                    'object' => $item,
×
56
                ],
×
57
            ]);
×
58

59
            $result = ($this->serializeStage)($item, $resourceClass, $operation, $resolverContext);
×
60

61
            $subscriptionId = $this->subscriptionManager->retrieveSubscriptionId($resolverContext, $result);
×
62

63
            if ($subscriptionId && ($mercure = $operation->getMercure())) {
×
64
                if (!$this->mercureSubscriptionIriGenerator) {
×
65
                    throw new \LogicException('Cannot use Mercure for subscriptions when MercureBundle is not installed. Try running "composer require mercure".');
×
66
                }
67

68
                $hub = \is_array($mercure) ? ($mercure['hub'] ?? null) : null;
×
69
                $result['mercureUrl'] = $this->mercureSubscriptionIriGenerator->generateMercureUrl($subscriptionId, $hub);
×
70
            }
71

72
            return $result;
×
73
        };
×
74
    }
75
}
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

© 2026 Coveralls, Inc