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

api-platform / core / 7930644932

16 Feb 2024 12:36PM UTC coverage: 66.683% (+0.005%) from 66.678%
7930644932

push

github

web-flow
fix: return null instead of exception for GraphQL Query operation (#6118)

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

53 existing lines in 19 files now uncovered.

16304 of 24450 relevant lines covered (66.68%)

37.74 hits per line

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

80.95
/src/Symfony/EventListener/QueryParameterValidateListener.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\Symfony\EventListener;
15

16
use ApiPlatform\Api\QueryParameterValidator\QueryParameterValidator;
17
use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions;
18
use ApiPlatform\Doctrine\Orm\State\Options;
19
use ApiPlatform\Metadata\CollectionOperationInterface;
20
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
21
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
22
use ApiPlatform\State\Util\RequestParser;
23
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
24
use Symfony\Component\HttpKernel\Event\RequestEvent;
25

26
/**
27
 * Validates query parameters depending on filter description.
28
 *
29
 * @author Julien Deniau <julien.deniau@mapado.com>
30
 */
31
final class QueryParameterValidateListener
32
{
33
    use OperationRequestInitiatorTrait;
34

35
    public const OPERATION_ATTRIBUTE_KEY = 'query_parameter_validate';
36

37
    public function __construct(private readonly QueryParameterValidator $queryParameterValidator, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
38
    {
39
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
136✔
40
    }
41

42
    public function onKernelRequest(RequestEvent $event): void
43
    {
44
        $request = $event->getRequest();
136✔
45

46
        if (
47
            !$request->isMethodSafe()
136✔
48
            || !($attributes = RequestAttributesExtractor::extractAttributes($request))
136✔
49
            || 'GET' !== $request->getMethod()
136✔
50
            || $request->attributes->get('_api_platform_disable_listeners')
136✔
51
        ) {
52
            return;
72✔
53
        }
54

55
        $operation = $this->initializeOperation($request);
76✔
56
        if ('api_platform.symfony.main_controller' === $operation?->getController()) {
76✔
UNCOV
57
            return;
42✔
58
        }
59

60
        if (!($operation?->getQueryParameterValidationEnabled() ?? true) || !$operation instanceof CollectionOperationInterface) {
34✔
61
            return;
15✔
62
        }
63

64
        $queryString = RequestParser::getQueryString($request);
22✔
65
        $queryParameters = $queryString ? RequestParser::parseRequestParams($queryString) : [];
22✔
66

67
        $class = $attributes['resource_class'];
22✔
68

69
        if ($options = $operation->getStateOptions()) {
22✔
70
            if ($options instanceof Options && $options->getEntityClass()) {
×
71
                $class = $options->getEntityClass();
×
72
            }
73

74
            if ($options instanceof ODMOptions && $options->getDocumentClass()) {
×
75
                $class = $options->getDocumentClass();
×
76
            }
77
        }
78

79
        $this->queryParameterValidator->validateFilters($class, $operation->getFilters() ?? [], $queryParameters);
22✔
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