Skip to content

Commit 6fc97d3

Browse files
authored
Merge pull request #772 from mfn/mfn-exe-mw-make
Add command to make an execution middleware
2 parents 6a056c1 + 48675cf commit 6fc97d3

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ CHANGELOG
8383
new: `public function queryAndReturnResult(string $query, ?array $variables = null, array $opts = []): ExecutionResult`
8484

8585
### Added
86+
- Command to make an exection middleware [\#772 / mfn](https://github.com/rebing/graphql-laravel/pull/772)
8687
- The primary execution of the GraphQL request is now piped through middlewares [\#762 / crissi and mfn](https://github.com/rebing/graphql-laravel/pull/762)\
8788
This allows greater flexibility for enabling/disabling certain functionality
8889
as well as bringing in new features without having to open up the library.

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,11 @@ parameters:
19401940
count: 1
19411941
path: tests/Unit/Console/EnumMakeCommandTest.php
19421942

1943+
-
1944+
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\Console\\\\ExecutionMiddlewareMakeCommandTest\\:\\:dataForMakeCommand\\(\\) return type has no value type specified in iterable type array\\.$#"
1945+
count: 1
1946+
path: tests/Unit/Console/ExecutionMiddlewareMakeCommandTest.php
1947+
19431948
-
19441949
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\Console\\\\InputMakeCommandTest\\:\\:dataForMakeCommand\\(\\) return type has no value type specified in iterable type array\\.$#"
19451950
count: 1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
namespace Rebing\GraphQL\Console;
5+
6+
use Illuminate\Console\GeneratorCommand;
7+
8+
class ExecutionMiddlewareMakeCommand extends GeneratorCommand
9+
{
10+
protected $signature = 'make:graphql:executionMiddleware {name}';
11+
protected $description = 'Create a new GraphQL execution middleware class';
12+
protected $type = 'ExecutionMiddleware';
13+
14+
protected function getStub()
15+
{
16+
return __DIR__ . '/stubs/executionMiddleware.stub';
17+
}
18+
19+
protected function getDefaultNamespace($rootNamespace)
20+
{
21+
return $rootNamespace . '\GraphQL\Middleware\Execution';
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
namespace DummyNamespace;
5+
6+
use Closure;
7+
use GraphQL\Executor\ExecutionResult;
8+
use GraphQL\Type\Schema;
9+
use Rebing\GraphQL\Support\ExecutionMiddleware\AbstractExecutionMiddleware;
10+
use Rebing\GraphQL\Support\OperationParams;
11+
12+
class DummyClass extends AbstractExecutionMiddleware
13+
{
14+
public function handle(string $schemaName, Schema $schema, OperationParams $params, $rootValue, $contextValue, Closure $next): ExecutionResult
15+
{
16+
return $next($schemaName, $schema, $params, $rootValue, $contextValue);
17+
}
18+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
namespace Rebing\GraphQL\Tests\Unit\Console;
5+
6+
use Rebing\GraphQL\Console\ExecutionMiddlewareMakeCommand;
7+
use Rebing\GraphQL\Tests\Support\Traits\MakeCommandAssertionTrait;
8+
use Rebing\GraphQL\Tests\TestCase;
9+
10+
class ExecutionMiddlewareMakeCommandTest extends TestCase
11+
{
12+
use MakeCommandAssertionTrait;
13+
14+
/**
15+
* @dataProvider dataForMakeCommand
16+
*/
17+
public function testCommand(
18+
string $inputName,
19+
string $expectedFilename,
20+
string $expectedClassDefinition
21+
): void {
22+
$this->assertMakeCommand(
23+
'ExecutionMiddleware',
24+
ExecutionMiddlewareMakeCommand::class,
25+
$inputName,
26+
$expectedFilename,
27+
'App\\\\GraphQL\\\\Middleware\\\\Execution',
28+
$expectedClassDefinition
29+
);
30+
}
31+
32+
public function dataForMakeCommand(): array
33+
{
34+
return [
35+
'Example' => [
36+
'inputName' => 'Example',
37+
'expectedFilename' => 'GraphQL/Middleware/Execution/Example.php',
38+
'expectedClassDefinition' => 'Example extends AbstractExecutionMiddleware',
39+
],
40+
'ExampleMiddleware' => [
41+
'inputName' => 'ExampleMiddleware',
42+
'expectedFilename' => 'GraphQL/Middleware/Execution/ExampleMiddleware.php',
43+
'expectedClassDefinition' => 'ExampleMiddleware extends AbstractExecutionMiddleware',
44+
],
45+
];
46+
}
47+
}

0 commit comments

Comments
 (0)