This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
366 additions
and
113 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Error\Handler; | ||
|
||
use Digia\GraphQL\Execution\ExecutionContext; | ||
use Digia\GraphQL\Execution\ExecutionException; | ||
|
||
abstract class AbstractErrorMiddleware implements ErrorMiddlewareInterface | ||
{ | ||
/** | ||
* @param \Throwable $exception | ||
* @param callable $next | ||
* @return mixed | ||
*/ | ||
public function handleError(\Throwable $exception, callable $next) | ||
{ | ||
} | ||
|
||
/** | ||
* @param ExecutionException $exception | ||
* @param ExecutionContext $context | ||
* @return mixed | ||
*/ | ||
public function handleExecutionError(ExecutionException $exception, ExecutionContext $context, callable $next) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Error\Handler; | ||
|
||
use Digia\GraphQL\Execution\ExecutionContext; | ||
use Digia\GraphQL\Execution\ExecutionException; | ||
|
||
class CallableMiddleware extends AbstractErrorMiddleware | ||
{ | ||
/** | ||
* @var callable | ||
*/ | ||
protected $handleCallback; | ||
|
||
/** | ||
* CallableMiddleware constructor. | ||
* @param callable $handleCallback | ||
*/ | ||
public function __construct(callable $handleCallback) | ||
{ | ||
$this->handleCallback = $handleCallback; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function handleExecutionError(ExecutionException $exception, ExecutionContext $context, callable $next) | ||
{ | ||
return \call_user_func($this->handleCallback, $exception, $context, $next); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Error\Handler; | ||
|
||
use Digia\GraphQL\Execution\ExecutionContext; | ||
use Digia\GraphQL\Execution\ExecutionException; | ||
|
||
class ErrorHandler implements ErrorHandlerInterface | ||
{ | ||
/** | ||
* @var ErrorMiddlewareInterface[] | ||
*/ | ||
protected $middleware = []; | ||
|
||
/** | ||
* ErrorHandler constructor. | ||
* @param ErrorMiddlewareInterface[] $middleware | ||
*/ | ||
public function __construct(array $middleware) | ||
{ | ||
foreach ($middleware as $mw) { | ||
$this->addMiddleware($mw); | ||
} | ||
} | ||
|
||
/** | ||
* @param \Throwable $exception | ||
*/ | ||
public function handleError(\Throwable $exception) | ||
{ | ||
$next = function () { | ||
// NO-OP | ||
}; | ||
|
||
foreach ($this->middleware as $middleware) { | ||
$next = function (\Throwable $exception) use ($middleware, $next) { | ||
return $middleware->handleError($exception, $next); | ||
}; | ||
} | ||
|
||
\call_user_func($next, $exception); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function handleExecutionError(ExecutionException $exception, ExecutionContext $context) | ||
{ | ||
$next = function () { | ||
// NO-OP | ||
}; | ||
|
||
foreach ($this->middleware as $middleware) { | ||
$next = function (ExecutionException $exception, ExecutionContext $context) use ($middleware, $next) { | ||
return $middleware->handleExecutionError($exception, $context, $next); | ||
}; | ||
} | ||
|
||
\call_user_func($next, $exception, $context); | ||
} | ||
|
||
/** | ||
* @param ErrorMiddlewareInterface $middleware | ||
*/ | ||
protected function addMiddleware(ErrorMiddlewareInterface $middleware) | ||
{ | ||
\array_unshift($this->middleware, $middleware); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Error\Handler; | ||
|
||
use Digia\GraphQL\Execution\ExecutionContext; | ||
use Digia\GraphQL\Execution\ExecutionException; | ||
|
||
interface ErrorHandlerInterface | ||
{ | ||
/** | ||
* @param \Throwable $exception | ||
*/ | ||
public function handleError(\Throwable $exception); | ||
|
||
/** | ||
* @param ExecutionException $exception | ||
* @param ExecutionContext $context | ||
*/ | ||
public function handleExecutionError(ExecutionException $exception, ExecutionContext $context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Digia\GraphQL\Error\Handler; | ||
|
||
use Digia\GraphQL\Execution\ExecutionContext; | ||
use Digia\GraphQL\Execution\ExecutionException; | ||
|
||
interface ErrorMiddlewareInterface | ||
{ | ||
/** | ||
* @param \Throwable $exception | ||
* @param callable $next | ||
* @return mixed | ||
*/ | ||
public function handleError(\Throwable $exception, callable $next); | ||
|
||
/** | ||
* @param ExecutionException $exception | ||
* @param ExecutionContext $context | ||
* @return mixed | ||
*/ | ||
public function handleExecutionError(ExecutionException $exception, ExecutionContext $context, callable $next); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.