Skip to content

Commit c4ef425

Browse files
authored
Merge pull request #1178 from sparklink-pro/master
Fix Arguments order of the method matter
2 parents e16d86d + 6dac5d3 commit c4ef425

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/Config/Parser/MetadataParser/MetadataParser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,12 @@ private static function guessType(ReflectionClass $reflectionClass, Reflector $r
976976
private static function guessArgs(
977977
ReflectionClass $reflectionClass,
978978
ReflectionMethod $method,
979-
array $arguments,
979+
array $currentArguments,
980980
): array {
981+
$arguments = [];
981982
foreach ($method->getParameters() as $index => $parameter) {
982-
if (array_key_exists($parameter->getName(), $arguments)) {
983+
if (array_key_exists($parameter->getName(), $currentArguments)) {
984+
$arguments[$parameter->getName()] = $currentArguments[$parameter->getName()];
983985
continue;
984986
}
985987

tests/Config/Parser/MetadataParserTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,17 @@ public function testProviders(): void
361361
'access' => '@=default_access',
362362
'public' => '@=default_public',
363363
],
364+
'planet_getNextPlanet' => [
365+
'type' => 'Json',
366+
'args' => [
367+
'planetId' => ['type' => 'Int!'],
368+
'minDistance' => ['type' => 'Int!'],
369+
'maxDistance' => ['type' => 'Int!'],
370+
],
371+
'resolve' => "@=call(service('Overblog\\\\GraphQLBundle\\\\Tests\\\\Config\\\\Parser\\\\fixtures\\\\annotations\\\\Repository\\\\PlanetRepository').getNextPlanet, arguments({planetId: \"Int!\", minDistance: \"Int!\", maxDistance: \"Int!\"}, args))",
372+
'access' => '@=default_access',
373+
'public' => '@=default_public',
374+
],
364375
],
365376
]);
366377

@@ -475,7 +486,7 @@ public function testArgsAndReturnGuessing(): void
475486
'away' => ['type' => 'Boolean', 'defaultValue' => false],
476487
'maxDistance' => ['type' => 'Float', 'defaultValue' => null],
477488
],
478-
'resolve' => '@=call(value.getCasualties, arguments({raceId: "String!", areaId: "Int!", dayStart: "Int", dayEnd: "Int", nameStartingWith: "String", planet: "PlanetInput", away: "Boolean", maxDistance: "Float"}, args))',
489+
'resolve' => '@=call(value.getCasualties, arguments({areaId: "Int!", raceId: "String!", dayStart: "Int", dayEnd: "Int", nameStartingWith: "String", planet: "PlanetInput", away: "Boolean", maxDistance: "Float"}, args))',
479490
'complexity' => '@=childrenComplexity * 5',
480491
],
481492
],

tests/Config/Parser/fixtures/annotations/Repository/PlanetRepository.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,22 @@ public function getArmorResistance(): int
120120
{
121121
return 10;
122122
}
123+
124+
/**
125+
* @GQL\Query(type="Json")
126+
*
127+
* @GQL\Arg(name="maxDistance", type="Int!")
128+
* @GQL\Arg(name="planetId", type="Int!")
129+
*/
130+
#[GQL\Query(type: 'Json')]
131+
#[GQL\Arg(name: 'maxDistance', type: 'Int!')]
132+
#[GQL\Arg(name: 'planetId', type: 'Int!')]
133+
public function getNextPlanet(int $planetId, int $minDistance, int $maxDistance): array
134+
{
135+
return [
136+
'planetId' => $planetId,
137+
'minDistance' => $minDistance,
138+
'maxDistance' => $maxDistance,
139+
];
140+
}
123141
}

0 commit comments

Comments
 (0)