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

api-platform / core / 13925245599

18 Mar 2025 02:06PM UTC coverage: 61.074% (-0.9%) from 61.973%
13925245599

Pull #7031

github

web-flow
Merge 8990d8b26 into 7cb5a6db8
Pull Request #7031: fix: header parameter should be case insensitive

3 of 4 new or added lines in 1 file covered. (75.0%)

167 existing lines in 27 files now uncovered.

11314 of 18525 relevant lines covered (61.07%)

51.02 hits per line

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

0.0
/src/GraphQl/Resolver/Factory/CollectionResolverFactory.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\QueryCollectionResolverInterface;
17
use ApiPlatform\GraphQl\Resolver\Stage\ReadStageInterface;
18
use ApiPlatform\GraphQl\Resolver\Stage\SecurityPostDenormalizeStageInterface;
19
use ApiPlatform\GraphQl\Resolver\Stage\SecurityStageInterface;
20
use ApiPlatform\GraphQl\Resolver\Stage\SerializeStageInterface;
21
use ApiPlatform\Metadata\GraphQl\Operation;
22
use ApiPlatform\Metadata\GraphQl\Query;
23
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
24
use ApiPlatform\Metadata\Util\CloneTrait;
25
use ApiPlatform\State\Pagination\ArrayPaginator;
26
use GraphQL\Type\Definition\ResolveInfo;
27
use Psr\Container\ContainerInterface;
28

29
/**
30
 * Creates a function retrieving a collection to resolve a GraphQL query or a field returned by a mutation.
31
 *
32
 * @author Alan Poulain <contact@alanpoulain.eu>
33
 * @author Kévin Dunglas <dunglas@gmail.com>
34
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
35
 *
36
 * @deprecated
37
 */
38
final class CollectionResolverFactory implements ResolverFactoryInterface
39
{
40
    use CloneTrait;
41

42
    public function __construct(private readonly ReadStageInterface $readStage, private readonly SecurityStageInterface $securityStage, private readonly SecurityPostDenormalizeStageInterface $securityPostDenormalizeStage, private readonly SerializeStageInterface $serializeStage, private readonly ContainerInterface $queryResolverLocator)
43
    {
UNCOV
44
    }
×
45

46
    public function __invoke(?string $resourceClass = null, ?string $rootClass = null, ?Operation $operation = null, ?PropertyMetadataFactoryInterface $propertyMetadataFactory = null): callable
47
    {
UNCOV
48
        return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation): ?array {
×
49
            // If authorization has failed for a relation field (e.g. via ApiProperty security), the field is not present in the source: null can be returned directly to ensure the collection isn't in the response.
UNCOV
50
            if (null === $resourceClass || null === $rootClass || (null !== $source && !\array_key_exists($info->fieldName, $source))) {
×
51
                return null;
×
52
            }
53

UNCOV
54
            if (is_a($resourceClass, \BackedEnum::class, true) && $source && \array_key_exists($info->fieldName, $source)) {
×
55
                return $source[$info->fieldName];
×
56
            }
57

UNCOV
58
            $resolverContext = ['source' => $source, 'args' => $args, 'info' => $info, 'is_collection' => true, 'is_mutation' => false, 'is_subscription' => false];
×
59

UNCOV
60
            if ($operation instanceof Query && $operation->getNested() && !$operation->getResolver() && !$operation->getProvider() && $source && \array_key_exists($info->fieldName, $source)) {
×
61
                return ($this->serializeStage)(new ArrayPaginator($source[$info->fieldName], 0, \count($source[$info->fieldName])), $resourceClass, $operation, $resolverContext);
×
62
            }
63

UNCOV
64
            $collection = ($this->readStage)($resourceClass, $rootClass, $operation, $resolverContext);
×
UNCOV
65
            if (!is_iterable($collection)) {
×
66
                throw new \LogicException('Collection from read stage should be iterable.');
×
67
            }
68

UNCOV
69
            $queryResolverId = $operation->getResolver();
×
UNCOV
70
            if (null !== $queryResolverId) {
×
71
                /** @var QueryCollectionResolverInterface $queryResolver */
72
                $queryResolver = $this->queryResolverLocator->get($queryResolverId);
×
73
                $collection = $queryResolver($collection, $resolverContext);
×
74
            }
75

76
            // Only perform security stage on the top-level query
UNCOV
77
            if (null === $source) {
×
UNCOV
78
                ($this->securityStage)($resourceClass, $operation, $resolverContext + [
×
UNCOV
79
                    'extra_variables' => [
×
UNCOV
80
                        'object' => $collection,
×
UNCOV
81
                    ],
×
UNCOV
82
                ]);
×
UNCOV
83
                ($this->securityPostDenormalizeStage)($resourceClass, $operation, $resolverContext + [
×
UNCOV
84
                    'extra_variables' => [
×
UNCOV
85
                        'object' => $collection,
×
UNCOV
86
                        'previous_object' => $this->clone($collection),
×
UNCOV
87
                    ],
×
UNCOV
88
                ]);
×
89
            }
90

UNCOV
91
            return ($this->serializeStage)($collection, $resourceClass, $operation, $resolverContext);
×
UNCOV
92
        };
×
93
    }
94
}
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