• 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.21
/src/GraphQl/State/Provider/ResolverProvider.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\Provider;
15

16
use ApiPlatform\Metadata\CollectionOperationInterface;
17
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
18
use ApiPlatform\Metadata\Operation;
19
use ApiPlatform\Metadata\Util\ClassInfoTrait;
20
use ApiPlatform\State\ProviderInterface;
21
use Psr\Container\ContainerInterface;
22

23
/**
24
 * This provider calls a GraphQl resolver if defined.
25
 */
26
final class ResolverProvider implements ProviderInterface
27
{
28
    use ClassInfoTrait;
29

30
    public function __construct(private readonly ProviderInterface $decorated, private readonly ContainerInterface $queryResolverLocator)
31
    {
32
    }
161✔
33

34
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
35
    {
36
        $item = $this->decorated->provide($operation, $uriVariables, $context);
138✔
37

38
        if (!$operation instanceof GraphQlOperation || null === ($queryResolverId = $operation->getResolver())) {
121✔
39
            return $item;
105✔
40
        }
41

42
        /** @var \ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface $queryResolver */
UNCOV
43
        $queryResolver = $this->queryResolverLocator->get($queryResolverId);
16✔
UNCOV
44
        $item = $queryResolver($item, $context);
16✔
UNCOV
45
        if (!$operation instanceof CollectionOperationInterface) {
16✔
46
            // The item retrieved can be of another type when using an identifier (see Relay Nodes at query.feature:23)
UNCOV
47
            $this->getResourceClass($item, $operation->getOutput()['class'] ?? $operation->getClass(), \sprintf('Custom query resolver "%s"', $queryResolverId).' has to return an item of class %s but returned an item of class %s.');
13✔
48
        }
49

UNCOV
50
        return $item;
16✔
51
    }
52

53
    /**
54
     * @throws \UnexpectedValueException
55
     */
56
    private function getResourceClass(?object $item, ?string $resourceClass, string $errorMessage = 'Resolver only handles items of class %s but retrieved item is of class %s.'): string
57
    {
UNCOV
58
        if (null === $item) {
13✔
UNCOV
59
            if (null === $resourceClass) {
1✔
60
                throw new \UnexpectedValueException('Resource class cannot be determined.');
×
61
            }
62

UNCOV
63
            return $resourceClass;
1✔
64
        }
65

UNCOV
66
        $itemClass = $this->getObjectClass($item);
12✔
67

UNCOV
68
        if (null === $resourceClass) {
12✔
69
            return $itemClass;
×
70
        }
71

UNCOV
72
        if ($resourceClass !== $itemClass && !$item instanceof $resourceClass) {
12✔
73
            throw new \UnexpectedValueException(\sprintf($errorMessage, (new \ReflectionClass($resourceClass))->getShortName(), (new \ReflectionClass($itemClass))->getShortName()));
×
74
        }
75

UNCOV
76
        return $resourceClass;
12✔
77
    }
78
}
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