Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ CHANGELOG
new: `public function queryAndReturnResult(string $query, ?array $variables = null, array $opts = []): ExecutionResult`

### Added
- Command to make an exection middleware [\#772 / mfn](https://github.com/rebing/graphql-laravel/pull/772)
- The primary execution of the GraphQL request is now piped through middlewares [\#762 / crissi and mfn](https://github.com/rebing/graphql-laravel/pull/762)\
This allows greater flexibility for enabling/disabling certain functionality
as well as bringing in new features without having to open up the library.
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,11 @@ parameters:
count: 1
path: tests/Unit/Console/EnumMakeCommandTest.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\Console\\\\ExecutionMiddlewareMakeCommandTest\\:\\:dataForMakeCommand\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/Console/ExecutionMiddlewareMakeCommandTest.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\Console\\\\InputMakeCommandTest\\:\\:dataForMakeCommand\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
23 changes: 23 additions & 0 deletions src/Console/ExecutionMiddlewareMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types = 1);
namespace Rebing\GraphQL\Console;

use Illuminate\Console\GeneratorCommand;

class ExecutionMiddlewareMakeCommand extends GeneratorCommand
{
protected $signature = 'make:graphql:executionMiddleware {name}';
protected $description = 'Create a new GraphQL execution middleware class';
protected $type = 'ExecutionMiddleware';

protected function getStub()
{
return __DIR__ . '/stubs/executionMiddleware.stub';
}

protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\GraphQL\Middleware\Execution';
}
}
18 changes: 18 additions & 0 deletions src/Console/stubs/executionMiddleware.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types = 1);
namespace DummyNamespace;

use Closure;
use GraphQL\Executor\ExecutionResult;
use GraphQL\Type\Schema;
use Rebing\GraphQL\Support\ExecutionMiddleware\AbstractExecutionMiddleware;
use Rebing\GraphQL\Support\OperationParams;

class DummyClass extends AbstractExecutionMiddleware
{
public function handle(string $schemaName, Schema $schema, OperationParams $params, $rootValue, $contextValue, Closure $next): ExecutionResult
{
return $next($schemaName, $schema, $params, $rootValue, $contextValue);
}
}
47 changes: 47 additions & 0 deletions tests/Unit/Console/ExecutionMiddlewareMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);
namespace Rebing\GraphQL\Tests\Unit\Console;

use Rebing\GraphQL\Console\ExecutionMiddlewareMakeCommand;
use Rebing\GraphQL\Tests\Support\Traits\MakeCommandAssertionTrait;
use Rebing\GraphQL\Tests\TestCase;

class ExecutionMiddlewareMakeCommandTest extends TestCase
{
use MakeCommandAssertionTrait;

/**
* @dataProvider dataForMakeCommand
*/
public function testCommand(
string $inputName,
string $expectedFilename,
string $expectedClassDefinition
): void {
$this->assertMakeCommand(
'ExecutionMiddleware',
ExecutionMiddlewareMakeCommand::class,
$inputName,
$expectedFilename,
'App\\\\GraphQL\\\\Middleware\\\\Execution',
$expectedClassDefinition
);
}

public function dataForMakeCommand(): array
{
return [
'Example' => [
'inputName' => 'Example',
'expectedFilename' => 'GraphQL/Middleware/Execution/Example.php',
'expectedClassDefinition' => 'Example extends AbstractExecutionMiddleware',
],
'ExampleMiddleware' => [
'inputName' => 'ExampleMiddleware',
'expectedFilename' => 'GraphQL/Middleware/Execution/ExampleMiddleware.php',
'expectedClassDefinition' => 'ExampleMiddleware extends AbstractExecutionMiddleware',
],
];
}
}