yireo/Yireo_CustomGraphQlQueryLimiter

Not working in 2.4.3 as there is a new validateFieldCount method introduced

youanden opened this issue · 1 comments

This method will pre-empt the query complexity checks in in the webonyx/graphql-php's DocumentValidator, and doesn't read from the defined system configuration values from this module.

Reference function:
https://github.com/magento/magento2/blob/2.4.3/lib/internal/Magento/Framework/GraphQl/Query/QueryComplexityLimiter.php#L86

    public function validateFieldCount(string $query): void
    {
        if (!empty($query)) {
            $totalFieldCount = 0;
            $queryAst = Parser::parse(new Source($query ?: '', 'GraphQL'));
            Visitor::visit(
                $queryAst,
                [
                    'leave' => [
                        NodeKind::FIELD => function (Node $node) use (&$totalFieldCount) {
                            $totalFieldCount++;
                        }
                    ]
                ]
            );

            if ($totalFieldCount > $this->queryComplexity) {
                throw new GraphQlInputException(__(
                    'Max query complexity should be %1 but got %2.',
                    $this->queryComplexity,
                    $totalFieldCount
                ));
            }
        }
    }

Thanks. Indeed this failed with 2.4.3. I was meaning to fix this earlier, but wanted to make sure there were enough tests (mainly integration tests) to proof this was needed and that a fix would actually work. This is now delivered in 0.0.3 (released just now). Let me know if you find any other issue.