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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 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
    {
UNCOV
32
    }
148✔
33

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

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

42
        /** @var \ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface $queryResolver */
43
        $queryResolver = $this->queryResolverLocator->get($queryResolverId);
16✔
44
        $item = $queryResolver($item, $context);
16✔
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)
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

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
    {
58
        if (null === $item) {
13✔
59
            if (null === $resourceClass) {
1✔
60
                throw new \UnexpectedValueException('Resource class cannot be determined.');
×
61
            }
62

63
            return $resourceClass;
1✔
64
        }
65

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

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

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

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