• 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/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\Util\CloneTrait;
23
use GraphQL\Type\Definition\ResolveInfo;
24
use Psr\Container\ContainerInterface;
25

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

37
    public function __construct(private readonly ReadStageInterface $readStage, private readonly SecurityStageInterface $securityStage, private readonly SecurityPostDenormalizeStageInterface $securityPostDenormalizeStage, private readonly SerializeStageInterface $serializeStage, private readonly ContainerInterface $queryResolverLocator)
38
    {
39
    }
×
40

41
    public function __invoke(string $resourceClass = null, string $rootClass = null, Operation $operation = null): callable
42
    {
43
        return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation): ?array {
×
44
            // 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.
45
            if (null === $resourceClass || null === $rootClass || (null !== $source && !\array_key_exists($info->fieldName, $source))) {
×
46
                return null;
×
47
            }
48

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

51
            $collection = ($this->readStage)($resourceClass, $rootClass, $operation, $resolverContext);
×
52
            if (!is_iterable($collection)) {
×
53
                throw new \LogicException('Collection from read stage should be iterable.');
×
54
            }
55

56
            $queryResolverId = $operation->getResolver();
×
57
            if (null !== $queryResolverId) {
×
58
                /** @var QueryCollectionResolverInterface $queryResolver */
59
                $queryResolver = $this->queryResolverLocator->get($queryResolverId);
×
60
                $collection = $queryResolver($collection, $resolverContext);
×
61
            }
62

63
            // Only perform security stage on the top-level query
64
            if (null === $source) {
×
65
                ($this->securityStage)($resourceClass, $operation, $resolverContext + [
×
66
                    'extra_variables' => [
×
67
                        'object' => $collection,
×
68
                    ],
×
69
                ]);
×
70
                ($this->securityPostDenormalizeStage)($resourceClass, $operation, $resolverContext + [
×
71
                    'extra_variables' => [
×
72
                        'object' => $collection,
×
73
                        'previous_object' => $this->clone($collection),
×
74
                    ],
×
75
                ]);
×
76
            }
77

78
            return ($this->serializeStage)($collection, $resourceClass, $operation, $resolverContext);
×
79
        };
×
80
    }
81
}
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