• 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/ResolverFactory.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\Metadata\GraphQl\Mutation;
17
use ApiPlatform\Metadata\GraphQl\Operation;
18
use ApiPlatform\Metadata\GraphQl\Query;
19
use ApiPlatform\State\ProcessorInterface;
20
use ApiPlatform\State\ProviderInterface;
21
use GraphQL\Type\Definition\ResolveInfo;
22

23
class ResolverFactory implements ResolverFactoryInterface
24
{
25
    public function __construct(
26
        private readonly ProviderInterface $provider,
27
        private readonly ProcessorInterface $processor
28
    ) {
29
    }
×
30

31
    public function __invoke(string $resourceClass = null, string $rootClass = null, Operation $operation = null): callable
32
    {
33
        return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation) {
×
34
            // Data already fetched and normalized (field or nested resource)
35
            if ($body = $source[$info->fieldName] ?? null) {
×
36
                return $body;
×
37
            }
38

39
            if (null === $resourceClass && \array_key_exists($info->fieldName, $source ?? [])) {
×
40
                return $body;
×
41
            }
42

43
            // 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.
44
            if ($operation && (null === $resourceClass || null === $rootClass || (null !== $source && !\array_key_exists($info->fieldName, $source)))) {
×
45
                return null;
×
46
            }
47

48
            // Handles relay nodes
49
            $operation ??= new Query();
×
50

51
            $graphQlContext = [];
×
52
            $context = ['source' => $source, 'args' => $args, 'info' => $info, 'root_class' => $rootClass, 'graphql_context' => &$graphQlContext];
×
53

54
            if (null === $operation->canValidate()) {
×
55
                $operation = $operation->withValidate($operation instanceof Mutation);
×
56
            }
57

58
            $body = $this->provider->provide($operation, [], $context);
×
59

60
            if (null === $operation->canWrite()) {
×
61
                $operation = $operation->withWrite($operation instanceof Mutation && null !== $body);
×
62
            }
63

64
            return $this->processor->process($body, $operation, [], $context);
×
65
        };
×
66
    }
67
}
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