Skip to content

Commit 963c865

Browse files
authored
Merge pull request #1250 from rebing/mfn/authorized-fix-docs
Remove non-functional `$getSelectFields` parameter from `authorize()`
2 parents ff5eda5 + d521ac3 commit 963c865

11 files changed

Lines changed: 15 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ CHANGELOG
33

44
[Next release](https://github.com/rebing/graphql-laravel/compare/9.17.0...master)
55

6+
## Breaking changes
7+
- Remove `$getSelectFields` parameter from `Field::authorize()` [\#1250 / mfn](https://github.com/rebing/graphql-laravel/pull/1250)
8+
it has been non-functional since half a decade
9+
610
2026-03-21, 10.0.0-RC2
711
----------------------
812

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,12 +1620,11 @@ declare(strict_types = 1);
16201620
namespace App\GraphQL\Queries;
16211621

16221622
use Illuminate\Support\Facades\Auth;
1623-
use Closure;
16241623
use GraphQL\Type\Definition\ResolveInfo;
16251624

16261625
class UsersQuery extends Query
16271626
{
1628-
public function authorize($root, array $args, $ctx, ResolveInfo $resolveInfo = null, Closure $getSelectFields = null): bool
1627+
public function authorize($root, array $args, $ctx, ResolveInfo $resolveInfo = null): bool
16291628
{
16301629
// true, if logged in
16311630
return ! Auth::guest();
@@ -1642,12 +1641,11 @@ declare(strict_types = 1);
16421641
namespace App\GraphQL\Queries;
16431642

16441643
use Illuminate\Support\Facades\Auth;
1645-
use Closure;
16461644
use GraphQL\Type\Definition\ResolveInfo;
16471645

16481646
class UsersQuery extends Query
16491647
{
1650-
public function authorize($root, array $args, $ctx, ResolveInfo $resolveInfo = null, Closure $getSelectFields = null): bool
1648+
public function authorize($root, array $args, $ctx, ResolveInfo $resolveInfo = null): bool
16511649
{
16521650
if (isset($args['id'])) {
16531651
return Auth::id() == $args['id'];
@@ -1667,12 +1665,11 @@ declare(strict_types = 1);
16671665
namespace App\GraphQL\Queries;
16681666

16691667
use Illuminate\Support\Facades\Auth;
1670-
use Closure;
16711668
use GraphQL\Type\Definition\ResolveInfo;
16721669

16731670
class UsersQuery extends Query
16741671
{
1675-
public function authorize($root, array $args, $ctx, ResolveInfo $resolveInfo = null, Closure $getSelectFields = null): bool
1672+
public function authorize($root, array $args, $ctx, ResolveInfo $resolveInfo = null): bool
16761673
{
16771674
if (isset($args['id'])) {
16781675
return Auth::id() == $args['id'];

example/Auth/Authenticate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
trait Authenticate
88
{
9-
public function authorize(array $args)
9+
public function authorize($root, array $args, $ctx): bool
1010
{
1111
return !Auth::guest();
1212
}

phpstan.neon.dist

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ parameters:
3030
-
3131
message: '/Call to an undefined method Mockery\\/'
3232
identifier: method.notFound
33-
# tests/Database/AuthorizeArgsTests/TestAuthorizationArgsQuery.php
34-
-
35-
message: '/Trying to invoke Closure\|null but it might not be a callable/'
36-
identifier: callable.nonCallable
3733
# Mass ignore the raw array property access used in many tests for now
3834
# See also https://github.com/larastan/larastan/issues/611
3935
-

src/Support/Field.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class Field
3636
* @param array<string, mixed> $args
3737
* @param mixed $ctx
3838
*/
39-
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
39+
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null): bool
4040
{
4141
return true;
4242
}
@@ -247,7 +247,7 @@ protected function originalResolver(): ?Closure
247247
// 1 - the provided `args` of the query or type (if applicable), empty array otherwise
248248
// 2 - the `$contextValue` (usually set via a GraphQL execution middleware, e.g. `AddAuthUserContextValueMiddleware`)
249249
// 3 - \GraphQL\Type\Definition\ResolveInfo as provided by the underlying GraphQL PHP library
250-
// 4 (!) - added by this library, encapsulates creating a `SelectFields` instance
250+
// 4 (!) - added by this library later via DI, encapsulates creating a `SelectFields` instance; only available for resolve()
251251
$arguments = \func_get_args();
252252

253253
// Authorize first - prevents unauthenticated users from probing

tests/Database/AuthorizeArgsTests/AuthorizeArgsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function testAuthorizeArgs(): void
2727
GRAPHQL;
2828

2929
// All relevant test assertions are in \Rebing\GraphQL\Tests\Database\AuthorizeArgsTests\TestAuthorizationArgsQuery::authorize
30+
// expectErrors because resolve() returns void on a nonNull(string) field
3031
$this->httpGraphql($graphql, [
3132
'expectErrors' => true,
3233
]);

tests/Database/AuthorizeArgsTests/TestAuthorizationArgsQuery.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
declare(strict_types = 1);
44
namespace Rebing\GraphQL\Tests\Database\AuthorizeArgsTests;
55

6-
use Closure;
76
use GraphQL\Type\Definition\ResolveInfo;
87
use GraphQL\Type\Definition\Type;
98
use PHPUnit\Framework\Assert;
109
use Rebing\GraphQL\Support\Query;
11-
use Rebing\GraphQL\Support\SelectFields;
1210

1311
class TestAuthorizationArgsQuery extends Query
1412
{
@@ -38,7 +36,6 @@ public function authorize(
3836
array $args,
3937
$ctx,
4038
?ResolveInfo $resolveInfo = null,
41-
?Closure $getSelectFields = null,
4239
): bool {
4340
Assert::assertNull($root);
4441

@@ -51,9 +48,6 @@ public function authorize(
5148

5249
Assert::assertInstanceOf(ResolveInfo::class, $resolveInfo);
5350

54-
$selectFields = $getSelectFields();
55-
Assert::assertInstanceOf(SelectFields::class, $selectFields);
56-
5751
return true;
5852
}
5953

tests/Support/Objects/ExamplesAuthorizeMessageQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ExamplesAuthorizeMessageQuery extends Query
1818
/**
1919
* @param array<string,mixed> $args
2020
*/
21-
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
21+
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null): bool
2222
{
2323
return false;
2424
}

tests/Support/Objects/ExamplesAuthorizeQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ExamplesAuthorizeQuery extends Query
1818
/**
1919
* @param array<string,mixed> $args
2020
*/
21-
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
21+
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null): bool
2222
{
2323
return false;
2424
}

tests/Unit/ValidationAuthorizationTests/AliasedArgValidationMutation.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare(strict_types = 1);
44
namespace Rebing\GraphQL\Tests\Unit\ValidationAuthorizationTests;
55

6-
use Closure;
76
use GraphQL\Type\Definition\ResolveInfo;
87
use GraphQL\Type\Definition\Type;
98
use Rebing\GraphQL\Support\Mutation;
@@ -23,7 +22,7 @@ class AliasedArgValidationMutation extends Mutation
2322
/**
2423
* @param array<string,mixed> $args
2524
*/
26-
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null, ?Closure $getSelectFields = null): bool
25+
public function authorize($root, array $args, $ctx, ?ResolveInfo $resolveInfo = null): bool
2726
{
2827
return true;
2928
}

0 commit comments

Comments
 (0)