From 6dac5d3abbb7f0adb7dcb5572cd00dec74951dc5 Mon Sep 17 00:00:00 2001 From: Vincent Bouzeran Date: Wed, 3 Apr 2024 20:42:20 +0200 Subject: [PATCH] Fix #1177 --- .../Parser/MetadataParser/MetadataParser.php | 6 ++++-- tests/Config/Parser/MetadataParserTest.php | 13 ++++++++++++- .../Repository/PlanetRepository.php | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Config/Parser/MetadataParser/MetadataParser.php b/src/Config/Parser/MetadataParser/MetadataParser.php index fe906a474..9d9fe0b14 100644 --- a/src/Config/Parser/MetadataParser/MetadataParser.php +++ b/src/Config/Parser/MetadataParser/MetadataParser.php @@ -976,10 +976,12 @@ private static function guessType(ReflectionClass $reflectionClass, Reflector $r private static function guessArgs( ReflectionClass $reflectionClass, ReflectionMethod $method, - array $arguments, + array $currentArguments, ): array { + $arguments = []; foreach ($method->getParameters() as $index => $parameter) { - if (array_key_exists($parameter->getName(), $arguments)) { + if (array_key_exists($parameter->getName(), $currentArguments)) { + $arguments[$parameter->getName()] = $currentArguments[$parameter->getName()]; continue; } diff --git a/tests/Config/Parser/MetadataParserTest.php b/tests/Config/Parser/MetadataParserTest.php index c24695f21..d458b254e 100644 --- a/tests/Config/Parser/MetadataParserTest.php +++ b/tests/Config/Parser/MetadataParserTest.php @@ -361,6 +361,17 @@ public function testProviders(): void 'access' => '@=default_access', 'public' => '@=default_public', ], + 'planet_getNextPlanet' => [ + 'type' => 'Json', + 'args' => [ + 'planetId' => ['type' => 'Int!'], + 'minDistance' => ['type' => 'Int!'], + 'maxDistance' => ['type' => 'Int!'], + ], + 'resolve' => "@=call(service('Overblog\\\\GraphQLBundle\\\\Tests\\\\Config\\\\Parser\\\\fixtures\\\\annotations\\\\Repository\\\\PlanetRepository').getNextPlanet, arguments({planetId: \"Int!\", minDistance: \"Int!\", maxDistance: \"Int!\"}, args))", + 'access' => '@=default_access', + 'public' => '@=default_public', + ], ], ]); @@ -475,7 +486,7 @@ public function testArgsAndReturnGuessing(): void 'away' => ['type' => 'Boolean', 'defaultValue' => false], 'maxDistance' => ['type' => 'Float', 'defaultValue' => null], ], - 'resolve' => '@=call(value.getCasualties, arguments({raceId: "String!", areaId: "Int!", dayStart: "Int", dayEnd: "Int", nameStartingWith: "String", planet: "PlanetInput", away: "Boolean", maxDistance: "Float"}, args))', + 'resolve' => '@=call(value.getCasualties, arguments({areaId: "Int!", raceId: "String!", dayStart: "Int", dayEnd: "Int", nameStartingWith: "String", planet: "PlanetInput", away: "Boolean", maxDistance: "Float"}, args))', 'complexity' => '@=childrenComplexity * 5', ], ], diff --git a/tests/Config/Parser/fixtures/annotations/Repository/PlanetRepository.php b/tests/Config/Parser/fixtures/annotations/Repository/PlanetRepository.php index 33440da25..c24d48e21 100644 --- a/tests/Config/Parser/fixtures/annotations/Repository/PlanetRepository.php +++ b/tests/Config/Parser/fixtures/annotations/Repository/PlanetRepository.php @@ -120,4 +120,22 @@ public function getArmorResistance(): int { return 10; } + + /** + * @GQL\Query(type="Json") + * + * @GQL\Arg(name="maxDistance", type="Int!") + * @GQL\Arg(name="planetId", type="Int!") + */ + #[GQL\Query(type: 'Json')] + #[GQL\Arg(name: 'maxDistance', type: 'Int!')] + #[GQL\Arg(name: 'planetId', type: 'Int!')] + public function getNextPlanet(int $planetId, int $minDistance, int $maxDistance): array + { + return [ + 'planetId' => $planetId, + 'minDistance' => $minDistance, + 'maxDistance' => $maxDistance, + ]; + } }