File tree 3 files changed +17
-6
lines changed
tests/Unit/ValidationAuthorizationTests
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ CHANGELOG
43
43
- Replace global helper ` is_lumen ` with static class call ` \Rebing\GraphQL\Helpers::isLumen `
44
44
45
45
### Fixed
46
+ - Arguments are now validation before they're passed to ` authorize() ` [ \# 413] ( https://github.com/rebing/graphql-laravel/pull/413 )
46
47
- File uploads now correctly work with batched requests [ \# 397] ( https://github.com/rebing/graphql-laravel/pull/397 )
47
48
- Path multi-level support for Schemas works again [ \# 358] ( https://github.com/rebing/graphql-laravel/pull/358 )
48
49
- SelectFields correctly passes field arguments to the custom query [ \# 327] ( https://github.com/rebing/graphql-laravel/pull/327 )
Original file line number Diff line number Diff line change @@ -167,11 +167,6 @@ protected function getResolver(): ?Closure
167
167
$ arguments [1 ] = array_merge ($ arguments [1 ], $ arguments [2 ]);
168
168
}
169
169
170
- // Authorize
171
- if (call_user_func ($ authorize , $ arguments [1 ]) != true ) {
172
- throw new AuthorizationError ('Unauthorized ' );
173
- }
174
-
175
170
// Validate mutation arguments
176
171
if (method_exists ($ this , 'getRules ' )) {
177
172
$ args = Arr::get ($ arguments , 1 , []);
@@ -188,6 +183,11 @@ protected function getResolver(): ?Closure
188
183
}
189
184
}
190
185
186
+ // Authorize
187
+ if (call_user_func ($ authorize , $ arguments [1 ]) != true ) {
188
+ throw new AuthorizationError ('Unauthorized ' );
189
+ }
190
+
191
191
// Add the 'selects and relations' feature as 5th arg
192
192
if (isset ($ arguments [3 ])) {
193
193
$ arguments [] = function () use ($ arguments ): SelectFields {
Original file line number Diff line number Diff line change 4
4
5
5
namespace Rebing \GraphQL \Tests \Unit \ValidationAuthorizationTests ;
6
6
7
+ use Illuminate \Support \MessageBag ;
7
8
use Rebing \GraphQL \Tests \TestCase ;
8
9
9
10
class ValidationAuthorizationTest extends TestCase
@@ -23,7 +24,16 @@ public function testAuthorizeArgumentsInvalid(): void
23
24
],
24
25
]);
25
26
26
- $ this ->assertSame ('Unauthorized ' , $ result ['errors ' ][0 ]['message ' ]);
27
+ $ this ->assertSame ('validation ' , $ result ['errors ' ][0 ]['message ' ]);
28
+
29
+ /** @var MessageBag $messageBag */
30
+ $ messageBag = $ result ['errors ' ][0 ]['extensions ' ]['validation ' ];
31
+ $ expectedErrors = [
32
+ 'arg1 ' => [
33
+ 'The selected arg1 is invalid. ' ,
34
+ ],
35
+ ];
36
+ $ this ->assertSame ($ expectedErrors , $ messageBag ->messages ());
27
37
}
28
38
29
39
public function testAuthorizeArgumentsValid (): void
You can’t perform that action at this time.
0 commit comments