Skip to content

Commit

Permalink
Merge f1437c3 into 611f1c6
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Oct 17, 2019
2 parents 611f1c6 + f1437c3 commit daa2c0a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composer.json
Expand Up @@ -12,7 +12,9 @@
"php": ">=7.1",
"thecodingmachine/funky": "^1",
"thecodingmachine/graphqlite": "~4.0.0",
"thecodingmachine/doctrine-annotations-universal-module": "^1.1"
"thecodingmachine/doctrine-annotations-universal-module": "^1.1",
"zendframework/zend-diactoros": "^2",
"thecodingmachine/middleware-list-universal-module": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.3.1",
Expand Down
22 changes: 22 additions & 0 deletions src/GraphQLiteServiceProvider.php
Expand Up @@ -3,6 +3,9 @@
namespace TheCodingMachine;

use Doctrine\Common\Annotations\Reader;
use Psr\Http\Server\MiddlewareInterface;
use TheCodingMachine\GraphQLite\Http\Psr15GraphQLMiddlewareBuilder;
use TheCodingMachine\GraphQLite\Http\WebonyxGraphqlMiddleware;
use function extension_loaded;
use Psr\Container\ContainerInterface;
use Psr\SimpleCache\CacheInterface;
Expand Down Expand Up @@ -47,6 +50,9 @@
use TheCodingMachine\GraphQLite\TypeRegistry;
use TheCodingMachine\GraphQLite\Types\ArgumentResolver;
use TheCodingMachine\GraphQLite\Types\TypeResolver;
use TheCodingMachine\Funky\Annotations\Tag;
use TheCodingMachine\MiddlewareListServiceProvider;
use TheCodingMachine\MiddlewareOrder;

class GraphQLiteServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -97,4 +103,20 @@ public static function getSchemaFactory(

return $schemaFactory;
}

/**
* @Factory()
*/
public static function getMiddlewareBuilder(Schema $schema): Psr15GraphQLMiddlewareBuilder
{
return new Psr15GraphQLMiddlewareBuilder($schema);
}

/**
* @Factory(name=WebonyxGraphqlMiddleware::class,tags={@Tag(name=MiddlewareListServiceProvider::MIDDLEWARES_QUEUE, priority=MiddlewareOrder::ROUTER)})
*/
public static function getMiddleware(Psr15GraphQLMiddlewareBuilder $builder): MiddlewareInterface
{
return $builder->createMiddleware();
}
}
4 changes: 4 additions & 0 deletions tests/GraphQLiteServiceProviderTest.php
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\TestCase;
use Simplex\Container;
use TheCodingMachine\GraphQLite\Http\WebonyxGraphqlMiddleware;
use TheCodingMachine\GraphQLite\Schema;
use TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface;
use TheCodingMachine\GraphQLite\Security\AuthorizationServiceInterface;
Expand All @@ -25,5 +26,8 @@ public function testServiceProvider(): void

$schema = $container->get(Schema::class);
$this->assertInstanceOf(Schema::class, $schema);

$middleware = $container->get(WebonyxGraphqlMiddleware::class);
$this->assertInstanceOf(WebonyxGraphqlMiddleware::class, $middleware);
}
}

0 comments on commit daa2c0a

Please sign in to comment.