Skip to content

Commit 628034b

Browse files
authored
Merge pull request #845 from mfn/sforward-patch-4
Fix: "Add array type hint for $args in stub files"
2 parents 25b7e9c + 4804cb4 commit 628034b

File tree

9 files changed

+34
-31
lines changed

9 files changed

+34
-31
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ CHANGELOG
108108

109109
- `\Rebing\GraphQL\Support\ResolveInfoFieldsAndArguments` has been removed
110110
- `$getSelectFields` closure no longer takes a depth parameter
111+
112+
- The `$args` argument, of the `handle` method of the execution middlewares requires `array` as type.
113+
111114
### Added
112115
- Command to make an execution middleware [\#772 / mfn](https://github.com/rebing/graphql-laravel/pull/772)
113116
- Command to make a schema configuration [\#830 / matsn0w](https://github.com/rebing/graphql-laravel/pull/830)
@@ -127,6 +130,8 @@ CHANGELOG
127130
- Don't silence broken schemas when normalizing them for generating routes [\#766 / mfn](https://github.com/rebing/graphql-laravel/pull/766)
128131
- Lazy loading types has been enabled by default [\#758 / mfn](https://github.com/rebing/graphql-laravel/pull/758)
129132
- Make it easier to extend select fields [\#799 / crissi](https://github.com/rebing/graphql-laravel/pull/799)
133+
- The `$args` argument, of the `handle` method of the execution middlewares requires `array` as type [\#843 / sforward](https://github.com/rebing/graphql-laravel/pull/843)
134+
130135

131136
### Removed
132137
- The method `\Rebing\GraphQL\GraphQLServiceProvider::provides` was removed [\#769 / mfn](https://github.com/rebing/graphql-laravel/pull/769)\

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ class UserType extends GraphQLType
380380
'email' => [
381381
'type' => Type::string(),
382382
'description' => 'The email of user',
383-
'resolve' => function($root, $args) {
383+
'resolve' => function($root, array $args) {
384384
// If you want to resolve the field yourself,
385385
// it can be done here
386386
return strtolower($root->email);
@@ -397,7 +397,7 @@ class UserType extends GraphQLType
397397

398398
// You can also resolve a field by declaring a method in the class
399399
// with the following format resolve[FIELD_NAME]Field()
400-
protected function resolveEmailField($root, $args)
400+
protected function resolveEmailField($root, array $args)
401401
{
402402
return strtolower($root->email);
403403
}
@@ -481,7 +481,7 @@ class UsersQuery extends Query
481481
];
482482
}
483483

484-
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
484+
public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
485485
{
486486
if (isset($args['id'])) {
487487
return User::where('id' , $args['id'])->get();
@@ -568,7 +568,7 @@ class UpdateUserPasswordMutation extends Mutation
568568
];
569569
}
570570

571-
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
571+
public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
572572
{
573573
$user = User::find($args['id']);
574574
if(!$user) {
@@ -662,7 +662,7 @@ class UserProfilePhotoMutation extends Mutation
662662
];
663663
}
664664

665-
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
665+
public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
666666
{
667667
$file = $args['profilePicture'];
668668

@@ -1049,7 +1049,7 @@ class UsersQuery extends Query
10491049
];
10501050
}
10511051

1052-
public function resolve($root, $args, $context, ResolveInfo $info, SelectFields $fields, SomeClassThatDoLogging $logging)
1052+
public function resolve($root, array $args, $context, ResolveInfo $info, SelectFields $fields, SomeClassThatDoLogging $logging)
10531053
{
10541054
$logging->log('fetched user');
10551055

@@ -1100,7 +1100,7 @@ use Rebing\GraphQL\Support\Middleware;
11001100

11011101
class ResolvePage extends Middleware
11021102
{
1103-
public function handle($root, $args, $context, ResolveInfo $info, Closure $next)
1103+
public function handle($root, array $args, $context, ResolveInfo $info, Closure $next)
11041104
{
11051105
Paginator::currentPageResolver(function () use ($args) {
11061106
return $args['pagination']['page'] ?? 1;
@@ -1181,7 +1181,7 @@ use Rebing\GraphQL\Support\Middleware;
11811181

11821182
class Logstash extends Middleware
11831183
{
1184-
public function terminate($root, $args, $context, ResolveInfo $info, $result): void
1184+
public function terminate($root, array $args, $context, ResolveInfo $info, $result): void
11851185
{
11861186
Log::channel('logstash')->info('', (
11871187
collect([
@@ -1441,7 +1441,7 @@ class PictureField extends Field
14411441
];
14421442
}
14431443

1444-
protected function resolve($root, $args)
1444+
protected function resolve($root, array $args)
14451445
{
14461446
$width = isset($args['width']) ? $args['width']:100;
14471447
$height = isset($args['height']) ? $args['height']:100;
@@ -1530,7 +1530,7 @@ class FormattableDate extends Field
15301530
];
15311531
}
15321532

1533-
protected function resolve($root, $args): ?string
1533+
protected function resolve($root, array $args): ?string
15341534
{
15351535
$date = $root->{$this->getProperty()};
15361536

@@ -1645,7 +1645,7 @@ class UsersQuery extends Query
16451645
];
16461646
}
16471647

1648-
public function resolve($root, $args, $context, ResolveInfo $info, Closure $getSelectFields)
1648+
public function resolve($root, array $args, $context, ResolveInfo $info, Closure $getSelectFields)
16491649
{
16501650
/** @var SelectFields $fields */
16511651
$fields = $getSelectFields();
@@ -1826,7 +1826,7 @@ class PostsQuery extends Query
18261826

18271827
// ...
18281828

1829-
public function resolve($root, $args, $context, ResolveInfo $info, Closure $getSelectFields)
1829+
public function resolve($root, array $args, $context, ResolveInfo $info, Closure $getSelectFields)
18301830
{
18311831
$fields = $getSelectFields();
18321832

@@ -1878,7 +1878,7 @@ class PostsQuery extends Query
18781878

18791879
// ...
18801880

1881-
public function resolve($root, $args, $context, ResolveInfo $info, Closure $getSelectFields)
1881+
public function resolve($root, array $args, $context, ResolveInfo $info, Closure $getSelectFields)
18821882
{
18831883
$fields = $getSelectFields();
18841884

@@ -2379,7 +2379,7 @@ class UpdateUserMutation extends Mutation
23792379
];
23802380
}
23812381

2382-
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
2382+
public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
23832383
{
23842384
$user = User::find($args['id']);
23852385
$user->fill($args['input']));
@@ -2828,7 +2828,7 @@ public function type(): Type
28282828
);
28292829
}
28302830

2831-
public function resolve($root, $args)
2831+
public function resolve($root, array $args)
28322832
{
28332833
return [
28342834
'data' => Post::find($args['post_id']),

phpstan-baseline.neon

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ parameters:
185185
count: 1
186186
path: src/Support/Middleware.php
187187

188-
-
189-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Middleware\\:\\:handle\\(\\) has parameter \\$args with no typehint specified\\.$#"
190-
count: 1
191-
path: src/Support/Middleware.php
192-
193188
-
194189
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Middleware\\:\\:handle\\(\\) has parameter \\$context with no typehint specified\\.$#"
195190
count: 1
@@ -210,6 +205,11 @@ parameters:
210205
count: 1
211206
path: src/Support/Middleware.php
212207

208+
-
209+
message: "#^Parameter \\#2 \\$args of method Rebing\\\\GraphQL\\\\Support\\\\Middleware\\:\\:handle\\(\\) expects array\\<string, mixed\\>, Closure given\\.$#"
210+
count: 1
211+
path: src/Support/Middleware.php
212+
213213
-
214214
message: "#^Anonymous function never returns null so it can be removed from the return typehint\\.$#"
215215
count: 2
@@ -1070,11 +1070,6 @@ parameters:
10701070
count: 1
10711071
path: tests/Support/Objects/ExampleMiddleware.php
10721072

1073-
-
1074-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExampleMiddleware\\:\\:handle\\(\\) has parameter \\$args with no typehint specified\\.$#"
1075-
count: 1
1076-
path: tests/Support/Objects/ExampleMiddleware.php
1077-
10781073
-
10791074
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExampleMiddleware\\:\\:handle\\(\\) has parameter \\$context with no typehint specified\\.$#"
10801075
count: 1

src/Console/stubs/field.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DummyClass extends Field
1818
return Type::string();
1919
}
2020

21-
public function resolve($root, $args): string
21+
public function resolve($root, array $args): string
2222
{
2323
return 'test';
2424
}

src/Console/stubs/middleware.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use Rebing\GraphQL\Support\Middleware;
1010

1111
class DummyClass extends Middleware
1212
{
13-
public function handle($root, $args, $context, ResolveInfo $info, Closure $next)
13+
public function handle($root, array $args, $context, ResolveInfo $info, Closure $next)
1414
{
1515
return $next($root, $args, $context, $info);
1616
}

src/Console/stubs/mutation.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DummyClass extends Mutation
2929
];
3030
}
3131

32-
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
32+
public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
3333
{
3434
$fields = $getSelectFields();
3535
$select = $fields->getSelect();

src/Console/stubs/query.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DummyClass extends Query
2929
];
3030
}
3131

32-
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
32+
public function resolve($root, array $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
3333
{
3434
/** @var SelectFields $fields */
3535
$fields = $getSelectFields();

src/Support/Middleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
abstract class Middleware
1010
{
11-
public function handle($root, $args, $context, ResolveInfo $info, Closure $next)
11+
/**
12+
* @param array<string,mixed> $args
13+
*/
14+
public function handle($root, array $args, $context, ResolveInfo $info, Closure $next)
1215
{
1316
return $next($root, $args, $context, $info);
1417
}

tests/Support/Objects/ExampleMiddleware.php

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

1111
class ExampleMiddleware extends Middleware
1212
{
13-
public function handle($root, $args, $context, ResolveInfo $info, Closure $next)
13+
public function handle($root, array $args, $context, ResolveInfo $info, Closure $next)
1414
{
1515
if (4 === $args['index']) {
1616
$args['index'] = 0;

0 commit comments

Comments
 (0)