Skip to content

Commit

Permalink
Update Query.php (#90)
Browse files Browse the repository at this point in the history
* Update Query.php

Validation Rules should also apply to queries, just like it is for mutations.
The server should be able to catch validation errors and return proper messages whether the request is a query or a mutation.

* Update Field.php

* Update Query.php

* Update Mutation.php
  • Loading branch information
swinyx authored and Mikk Mihkel Nurges committed Apr 10, 2018
1 parent ebd67fe commit fa23181
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
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 {

}

0 comments on commit fa23181

Please sign in to comment.