Skip to content

Commit

Permalink
Added AstManipulator::findArguments().
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Oct 3, 2023
1 parent c83c1ee commit 543a3c3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/graphql/src/Utils/AstManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,29 @@ public function getField(
return $field;
}

/**
* @param callable(InputValueDefinitionNode|Argument|ArgumentNode): bool $closure
*
* @return array<string, ($node is FieldDefinitionNode ? InputValueDefinitionNode : ($node is FieldDefinition ? Argument : ArgumentNode))>
*/
public function findArguments(
FieldDefinitionNode|FieldDefinition|DirectiveNode $node,
callable $closure,
): array {
$arguments = [];
$args = $node instanceof FieldDefinitionNode || $node instanceof DirectiveNode
? $node->arguments
: $node->args;

foreach ($args as $arg) {
if ($closure($arg)) {
$arguments[$this->getName($arg)] = $arg;
}
}

return $arguments;
}

/**
* @param callable(InputValueDefinitionNode|Argument|ArgumentNode): bool $closure
*
Expand Down

0 comments on commit 543a3c3

Please sign in to comment.