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

api-platform / core / 13471447230

22 Feb 2025 09:00AM UTC coverage: 8.516%. Remained the same
13471447230

push

github

web-flow
feat: add checkMode parameter to control json schema validation (#6974)

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

10870 existing lines in 366 files now uncovered.

13370 of 156994 relevant lines covered (8.52%)

22.87 hits per line

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

100.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\GraphQl\State\Provider\NoopProvider;
17
use ApiPlatform\Metadata\DeleteOperationInterface;
18
use ApiPlatform\Metadata\GraphQl\Mutation;
19
use ApiPlatform\Metadata\GraphQl\Operation;
20
use ApiPlatform\Metadata\GraphQl\Query;
21
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
22
use ApiPlatform\State\Pagination\ArrayPaginator;
23
use ApiPlatform\State\ProcessorInterface;
24
use ApiPlatform\State\ProviderInterface;
25
use GraphQL\Type\Definition\ResolveInfo;
26

27
class ResolverFactory implements ResolverFactoryInterface
28
{
29
    public function __construct(
30
        private readonly ProviderInterface $provider,
31
        private readonly ProcessorInterface $processor,
32
    ) {
UNCOV
33
    }
300✔
34

35
    public function __invoke(?string $resourceClass = null, ?string $rootClass = null, ?Operation $operation = null, ?PropertyMetadataFactoryInterface $propertyMetadataFactory = null): callable
36
    {
UNCOV
37
        return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation, $propertyMetadataFactory) {
296✔
UNCOV
38
            if (\array_key_exists($info->fieldName, $source ?? [])) {
253✔
UNCOV
39
                $body = $source[$info->fieldName];
93✔
40

41
                // special treatment for nested resources without a resolver/provider
UNCOV
42
                if ($operation instanceof Query && $operation->getNested() && !$operation->getResolver() && (!$operation->getProvider() || NoopProvider::class === $operation->getProvider())) {
93✔
43
                    return \is_array($body) ? $this->resolve(
5✔
44
                        $source,
5✔
45
                        $args,
5✔
46
                        $info,
5✔
47
                        $rootClass,
5✔
48
                        $operation,
5✔
49
                        new ArrayPaginator($body, 0, \count($body))
5✔
50
                    ) : $body;
5✔
51
                }
52

UNCOV
53
                $propertyMetadata = $rootClass ? $propertyMetadataFactory?->create($rootClass, $info->fieldName) : null;
92✔
UNCOV
54
                $type = $propertyMetadata?->getBuiltinTypes()[0] ?? null;
92✔
55
                // Data already fetched and normalized (field or nested resource)
UNCOV
56
                if ($body || null === $resourceClass || ($type && !$type->isCollection())) {
92✔
UNCOV
57
                    return $body;
61✔
58
                }
59
            }
60

61
            // 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
62
            if ($operation && (null === $resourceClass || null === $rootClass || (null !== $source && !\array_key_exists($info->fieldName, $source)))) {
253✔
63
                return null;
4✔
64
            }
65

UNCOV
66
            return $this->resolve($source, $args, $info, $rootClass, $operation, null);
253✔
UNCOV
67
        };
296✔
68
    }
69

70
    private function resolve(?array $source, array $args, ResolveInfo $info, ?string $rootClass = null, ?Operation $operation = null, mixed $body = null)
71
    {
72
        // Handles relay nodes
UNCOV
73
        $operation ??= new Query();
253✔
74

UNCOV
75
        $graphQlContext = [];
253✔
UNCOV
76
        $context = ['source' => $source, 'args' => $args, 'info' => $info, 'root_class' => $rootClass, 'graphql_context' => &$graphQlContext];
253✔
77

UNCOV
78
        if (null === $operation->canValidate()) {
253✔
UNCOV
79
            $operation = $operation->withValidate($operation instanceof Mutation && !$operation instanceof DeleteOperationInterface);
246✔
80
        }
81

UNCOV
82
        $body ??= $this->provider->provide($operation, [], $context);
253✔
83

UNCOV
84
        if (null === $operation->canWrite()) {
229✔
UNCOV
85
            $operation = $operation->withWrite($operation instanceof Mutation && null !== $body);
227✔
86
        }
87

UNCOV
88
        return $this->processor->process($body, $operation, [], $context);
229✔
89
    }
90
}
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