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

api-platform / core / 8539788647

03 Apr 2024 01:43PM UTC coverage: 66.768% (+0.001%) from 66.767%
8539788647

push

github

web-flow
GraphQL: Errors with nullish ManyToOne-Relation when using new ResolverFactory (for version 3.2) (#6092)

* fix(graphql): null cases in ResolverFactory

* fix: make PropertyMetadataFactoryInterface nullable for backwards compatibility

* fix(graphql): pass propertyMetadataFactory from FieldsBuilder to ResolverFactory

* use getBuiltinTypes

---------

Co-authored-by: josef.wagner <josef.wagner@hf-solutions.co>

0 of 8 new or added lines in 2 files covered. (0.0%)

15 existing lines in 3 files now uncovered.

16399 of 24561 relevant lines covered (66.77%)

40.35 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\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
20
use ApiPlatform\State\ProcessorInterface;
21
use ApiPlatform\State\ProviderInterface;
22
use GraphQL\Type\Definition\ResolveInfo;
23

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

32
    public function __invoke(?string $resourceClass = null, ?string $rootClass = null, ?Operation $operation = null, ?PropertyMetadataFactoryInterface $propertyMetadataFactory = null): callable
33
    {
NEW
34
        return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation, $propertyMetadataFactory) {
×
NEW
35
            if (\array_key_exists($info->fieldName, $source ?? [])) {
×
NEW
36
                $body = $source[$info->fieldName];
×
37

NEW
38
                $propertyMetadata = $rootClass ? $propertyMetadataFactory?->create($rootClass, $info->fieldName) : null;
×
NEW
39
                $type = $propertyMetadata?->getBuiltinTypes()[0] ?? null;
×
40
                // Data already fetched and normalized (field or nested resource)
NEW
41
                if ($body || null === $resourceClass || ($type && !$type->isCollection())) {
×
NEW
42
                    return $body;
×
43
                }
44
            }
45

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

51
            // Handles relay nodes
52
            $operation ??= new Query();
×
53

54
            $graphQlContext = [];
×
55
            $context = ['source' => $source, 'args' => $args, 'info' => $info, 'root_class' => $rootClass, 'graphql_context' => &$graphQlContext];
×
56

57
            if (null === $operation->canValidate()) {
×
58
                $operation = $operation->withValidate($operation instanceof Mutation);
×
59
            }
60

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

63
            if (null === $operation->canWrite()) {
×
64
                $operation = $operation->withWrite($operation instanceof Mutation && null !== $body);
×
65
            }
66

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