Skip to content

Commit fa23181

Browse files
swinyxMikk Mihkel Nurges
authored andcommitted
Update Query.php (#90)
* 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
1 parent ebd67fe commit fa23181

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/Rebing/GraphQL/Support/Field.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,35 @@ public function args()
3333
return [];
3434
}
3535

36+
protected function rules(array $args = [])
37+
{
38+
return [];
39+
}
40+
41+
public function getRules()
42+
{
43+
$arguments = func_get_args();
44+
45+
$rules = call_user_func_array([$this, 'rules'], $arguments);
46+
$argsRules = [];
47+
foreach($this->args() as $name => $arg)
48+
{
49+
if(isset($arg['rules']))
50+
{
51+
if(is_callable($arg['rules']))
52+
{
53+
$argsRules[$name] = call_user_func_array($arg['rules'], $arguments);
54+
}
55+
else
56+
{
57+
$argsRules[$name] = $arg['rules'];
58+
}
59+
}
60+
}
61+
62+
return array_merge($argsRules, $rules);
63+
}
64+
3665
protected function getResolver()
3766
{
3867
if(!method_exists($this, 'resolve'))

src/Rebing/GraphQL/Support/Mutation.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,4 @@
44

55
class Mutation extends Field {
66

7-
protected function rules(array $args = [])
8-
{
9-
return [];
10-
}
11-
12-
public function getRules()
13-
{
14-
$arguments = func_get_args();
15-
16-
$rules = call_user_func_array([$this, 'rules'], $arguments);
17-
$argsRules = [];
18-
foreach($this->args() as $name => $arg)
19-
{
20-
if(isset($arg['rules']))
21-
{
22-
if(is_callable($arg['rules']))
23-
{
24-
$argsRules[$name] = call_user_func_array($arg['rules'], $arguments);
25-
}
26-
else
27-
{
28-
$argsRules[$name] = $arg['rules'];
29-
}
30-
}
31-
}
32-
33-
return array_merge($argsRules, $rules);
34-
}
35-
367
}

src/Rebing/GraphQL/Support/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
namespace Rebing\GraphQL\Support;
44

55
class Query extends Field {
6-
6+
77
}

0 commit comments

Comments
 (0)