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

api-platform / core / 10739011304

06 Sep 2024 01:11PM UTC coverage: 7.159% (-0.5%) from 7.645%
10739011304

push

github

web-flow
 feat(laravel): eloquent filters (search, date, equals, or) (#6593)

* feat(laravel): Eloquent filters search date or

* feat(laravel): eloquent filters order range equals afterdate

* fix(laravel): order afterDate filters

* temp

* test(laravel): filter with eloquent

---------

Co-authored-by: Nathan <nathan@les-tilleuls.coop>

0 of 144 new or added lines in 16 files covered. (0.0%)

4792 existing lines in 155 files now uncovered.

11736 of 163930 relevant lines covered (7.16%)

22.8 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
    }
414✔
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) {
408✔
UNCOV
38
            if (\array_key_exists($info->fieldName, $source ?? [])) {
344✔
UNCOV
39
                $body = $source[$info->fieldName];
135✔
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())) {
135✔
UNCOV
43
                    return \is_array($body) ? $this->resolve(
7✔
UNCOV
44
                        $source,
7✔
UNCOV
45
                        $args,
7✔
UNCOV
46
                        $info,
7✔
UNCOV
47
                        $rootClass,
7✔
UNCOV
48
                        $operation,
7✔
UNCOV
49
                        new ArrayPaginator($body, 0, \count($body))
7✔
UNCOV
50
                    ) : $body;
7✔
51
                }
52

UNCOV
53
                $propertyMetadata = $rootClass ? $propertyMetadataFactory?->create($rootClass, $info->fieldName) : null;
134✔
UNCOV
54
                $type = $propertyMetadata?->getBuiltinTypes()[0] ?? null;
134✔
55
                // Data already fetched and normalized (field or nested resource)
UNCOV
56
                if ($body || null === $resourceClass || ($type && !$type->isCollection())) {
134✔
UNCOV
57
                    return $body;
88✔
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)))) {
344✔
UNCOV
63
                return null;
6✔
64
            }
65

UNCOV
66
            return $this->resolve($source, $args, $info, $rootClass, $operation, null);
344✔
UNCOV
67
        };
408✔
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();
344✔
74

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

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

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

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

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