Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Rebing/GraphQL/Support/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ public function args()
return [];
}

protected function rules(array $args = [])
{
return [];
}

public function getRules()
{
$arguments = func_get_args();

$rules = call_user_func_array([$this, 'rules'], $arguments);
$argsRules = [];
foreach($this->args() as $name => $arg)
{
if(isset($arg['rules']))
{
if(is_callable($arg['rules']))
{
$argsRules[$name] = call_user_func_array($arg['rules'], $arguments);
}
else
{
$argsRules[$name] = $arg['rules'];
}
}
}

return array_merge($argsRules, $rules);
}

protected function getResolver()
{
if(!method_exists($this, 'resolve'))
Expand Down
29 changes: 0 additions & 29 deletions src/Rebing/GraphQL/Support/Mutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,4 @@

class Mutation extends Field {

protected function rules(array $args = [])
{
return [];
}

public function getRules()
{
$arguments = func_get_args();

$rules = call_user_func_array([$this, 'rules'], $arguments);
$argsRules = [];
foreach($this->args() as $name => $arg)
{
if(isset($arg['rules']))
{
if(is_callable($arg['rules']))
{
$argsRules[$name] = call_user_func_array($arg['rules'], $arguments);
}
else
{
$argsRules[$name] = $arg['rules'];
}
}
}

return array_merge($argsRules, $rules);
}

}
2 changes: 1 addition & 1 deletion src/Rebing/GraphQL/Support/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
namespace Rebing\GraphQL\Support;

class Query extends Field {

}