Skip to content

Commit

Permalink
Upgrade webonyx graphql to 15.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Sep 20, 2023
1 parent ebdbef7 commit 54dc801
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 25 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
"require": {
"php": "^8.1",
"psr/container": "^1.0|^2.0",
"psr/event-dispatcher": "^1.0",
"railt/event-dispatcher": "^2.0",
"railt/http": "^2.0",
"railt/http-factory": "^2.0",
"railt/http-middleware": "^2.0",
"railt/sdl": "^2.0",
"railt/type-system": "^2.0",
"symfony/event-dispatcher": "^5.4|^6.0"
"railt/type-system": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
26 changes: 12 additions & 14 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Railt\Foundation;

use Psr\EventDispatcher\EventDispatcherInterface;
use Railt\Contracts\Http\Middleware\MiddlewareInterface;
use Railt\EventDispatcher\EventDispatcher;
use Railt\Foundation\Connection\OnDestructor;
use Railt\Foundation\Event\Connection\ConnectionClosed;
use Railt\Foundation\Event\Connection\ConnectionEstablished;
Expand All @@ -18,8 +20,6 @@
use Railt\SDL\Compiler;
use Railt\SDL\CompilerInterface;
use Railt\TypeSystem\DictionaryInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

final class Application implements ApplicationInterface
{
Expand All @@ -32,6 +32,8 @@ final class Application implements ApplicationInterface

private readonly MutablePipelineInterface $pipeline;

private readonly EventDispatcherInterface $dispatcher;

/**
* @param iterable<array-key, MiddlewareInterface>|MutablePipelineInterface $middleware
* @param iterable<array-key, ExtensionInterface>|Repository $extensions
Expand All @@ -41,22 +43,18 @@ public function __construct(
private readonly CompilerInterface $compiler = new Compiler(),
iterable|MutablePipelineInterface $middleware = [],
iterable|Repository $extensions = [],
private readonly EventDispatcherInterface $dispatcher = new EventDispatcher(),
?EventDispatcherInterface $dispatcher = null,
) {
if (!$middleware instanceof MutablePipelineInterface) {
$middleware = new Pipeline($middleware);
}

if (!$extensions instanceof Repository) {
$extensions = new Repository($extensions);
}

$this->pipeline = !$middleware instanceof MutablePipelineInterface
? new Pipeline($middleware)
: $middleware;
$this->extensions = !$extensions instanceof Repository
? new Repository($extensions)
: $extensions;
$this->dispatcher = new EventDispatcher($dispatcher);
/** @psalm-suppress PropertyTypeCoercion */
$this->connections = new \WeakMap();

$this->extensions = $extensions;
$this->pipeline = $middleware;

$this->bootDefaultExtensions();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Railt\Contracts\Http\ResponseInterface;
use Railt\Http\Middleware\PipelineInterface;
use Railt\TypeSystem\DictionaryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Railt\EventDispatcher\EventDispatcherInterface;

final class Connection implements ConnectionInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Railt\Contracts\Http\Middleware\RequestHandlerInterface;
use Railt\TypeSystem\DictionaryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Railt\EventDispatcher\EventDispatcherInterface;

interface ExecutorInterface
{
Expand Down
19 changes: 17 additions & 2 deletions src/Extension/DefaultValueResolverExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@
use Railt\TypeSystem\ListType;
use Railt\TypeSystem\NonNullType;
use Railt\TypeSystem\WrappingTypeInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Railt\EventDispatcher\EventDispatcherInterface;

final class DefaultValueResolverExtension implements ExtensionInterface
{
/**
* @var \Closure(FieldResolving):void
*/
private readonly \Closure $fieldResolving;

public function __construct()
{
$this->fieldResolving = $this->tryFieldResolving(...);
}

public function load(EventDispatcherInterface $dispatcher): void
{
$dispatcher->addListener(FieldResolving::class, $this->tryFieldResolving(...));
$dispatcher->addListener(FieldResolving::class, $this->fieldResolving);
}

public function unload(EventDispatcherInterface $dispatcher): void
{
$dispatcher->removeListener(FieldResolving::class, $this->fieldResolving);
}

private function tryFieldResolving(FieldResolving $event): void
Expand Down
4 changes: 3 additions & 1 deletion src/Extension/ExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Railt\Foundation\Extension;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Railt\EventDispatcher\EventDispatcherInterface;

interface ExtensionInterface
{
public function load(EventDispatcherInterface $dispatcher): void;

public function unload(EventDispatcherInterface $dispatcher): void;
}
15 changes: 13 additions & 2 deletions src/Extension/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Railt\Foundation\Extension;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Railt\EventDispatcher\EventDispatcherInterface;

/**
* @template-implements \IteratorAggregate<array-key, ExtensionInterface>
*/
final class Repository implements ExtensionInterface, \IteratorAggregate, \Countable
final class Repository implements RepositoryInterface, \IteratorAggregate
{
/**
* @var list<ExtensionInterface>
Expand Down Expand Up @@ -46,6 +46,17 @@ public function load(EventDispatcherInterface $dispatcher): void
}
}

public function unload(EventDispatcherInterface $dispatcher): void
{
while ($this->loaded !== []) {
$extension = \array_shift($this->loaded);

$extension->unload($dispatcher);

$this->registered[] = $extension;
}
}

public function count(): int
{
return \count($this->loaded) + \count($this->registered);
Expand Down
16 changes: 16 additions & 0 deletions src/Extension/RepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Railt\Foundation\Extension;

/**
* @template-implements \Traversable<array-key, ExtensionInterface>
*/
interface RepositoryInterface extends ExtensionInterface, \Traversable, \Countable
{
/**
* @param ExtensionInterface $extension
*/
public function register(ExtensionInterface $extension): void;
}
2 changes: 1 addition & 1 deletion tests/Architecture/ComposerDependenciesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testDependencies(): Rule
Selector::namespace('Railt\Http\Middleware'),
Selector::namespace('Railt\SDL'),
Selector::namespace('Railt\TypeSystem'),
Selector::namespace('Symfony\Component\EventDispatcher'),
Selector::namespace('Railt\EventDispatcher'),
)
;
}
Expand Down

0 comments on commit 54dc801

Please sign in to comment.