mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-21 20:36:05 +03:00
Fix CS in src/Server
This commit is contained in:
parent
a95d2ad140
commit
7ba98ce773
@ -17,6 +17,7 @@ use GraphQL\Language\AST\DocumentNode;
|
||||
use GraphQL\Language\Parser;
|
||||
use GraphQL\Utils\AST;
|
||||
use GraphQL\Utils\Utils;
|
||||
use JsonSerializable;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
@ -52,9 +53,11 @@ class Helper
|
||||
*
|
||||
* For PSR-7 request parsing use `parsePsrRequest()` instead.
|
||||
*
|
||||
* @api
|
||||
* @return OperationParams|OperationParams[]
|
||||
*
|
||||
* @throws RequestError
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function parseHttpRequest(?callable $readRawBodyFn = null)
|
||||
{
|
||||
@ -104,12 +107,15 @@ class Helper
|
||||
*
|
||||
* Returned value is a suitable input for `executeOperation` or `executeBatch` (if array)
|
||||
*
|
||||
* @api
|
||||
* @param string $method
|
||||
* @param mixed[] $bodyParams
|
||||
* @param mixed[] $queryParams
|
||||
*
|
||||
* @return OperationParams|OperationParams[]
|
||||
*
|
||||
* @throws RequestError
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function parseRequestParams($method, array $bodyParams, array $queryParams)
|
||||
{
|
||||
@ -136,8 +142,9 @@ class Helper
|
||||
* Checks validity of OperationParams extracted from HTTP request and returns an array of errors
|
||||
* if params are invalid (or empty array when params are valid)
|
||||
*
|
||||
* @api
|
||||
* @return Error[]
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function validateOperationParams(OperationParams $params)
|
||||
{
|
||||
@ -185,9 +192,9 @@ class Helper
|
||||
* Executes GraphQL operation with given server configuration and returns execution result
|
||||
* (or promise when promise adapter is different from SyncPromiseAdapter)
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @return ExecutionResult|Promise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function executeOperation(ServerConfig $config, OperationParams $op)
|
||||
{
|
||||
@ -205,9 +212,11 @@ class Helper
|
||||
* Executes batched GraphQL operations with shared promise queue
|
||||
* (thus, effectively batching deferreds|promises of all queries at once)
|
||||
*
|
||||
* @api
|
||||
* @param OperationParams[] $operations
|
||||
*
|
||||
* @return ExecutionResult|ExecutionResult[]|Promise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function executeBatch(ServerConfig $config, array $operations)
|
||||
{
|
||||
@ -230,6 +239,7 @@ class Helper
|
||||
|
||||
/**
|
||||
* @param bool $isBatch
|
||||
*
|
||||
* @return Promise
|
||||
*/
|
||||
private function promiseToExecuteOperation(
|
||||
@ -252,7 +262,7 @@ class Helper
|
||||
if (! empty($errors)) {
|
||||
$errors = Utils::map(
|
||||
$errors,
|
||||
function (RequestError $err) {
|
||||
static function (RequestError $err) {
|
||||
return Error::createLocatedError($err, null, null);
|
||||
}
|
||||
);
|
||||
@ -294,7 +304,7 @@ class Helper
|
||||
);
|
||||
}
|
||||
|
||||
$applyErrorHandling = function (ExecutionResult $result) use ($config) {
|
||||
$applyErrorHandling = static function (ExecutionResult $result) use ($config) {
|
||||
if ($config->getErrorsHandler()) {
|
||||
$result->setErrorsHandler($config->getErrorsHandler());
|
||||
}
|
||||
@ -315,6 +325,7 @@ class Helper
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*
|
||||
* @throws RequestError
|
||||
*/
|
||||
private function loadPersistedQuery(ServerConfig $config, OperationParams $operationParams)
|
||||
@ -341,6 +352,7 @@ class Helper
|
||||
|
||||
/**
|
||||
* @param string $operationType
|
||||
*
|
||||
* @return mixed[]|null
|
||||
*/
|
||||
private function resolveValidationRules(
|
||||
@ -368,13 +380,14 @@ class Helper
|
||||
|
||||
/**
|
||||
* @param string $operationType
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function resolveRootValue(ServerConfig $config, OperationParams $params, DocumentNode $doc, $operationType)
|
||||
{
|
||||
$root = $config->getRootValue();
|
||||
|
||||
if ($root instanceof \Closure) {
|
||||
if (is_callable($root)) {
|
||||
$root = $root($params, $doc, $operationType);
|
||||
}
|
||||
|
||||
@ -383,6 +396,7 @@ class Helper
|
||||
|
||||
/**
|
||||
* @param string $operationType
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function resolveContextValue(
|
||||
@ -393,7 +407,7 @@ class Helper
|
||||
) {
|
||||
$context = $config->getContext();
|
||||
|
||||
if ($context instanceof \Closure) {
|
||||
if (is_callable($context)) {
|
||||
$context = $context($params, $doc, $operationType);
|
||||
}
|
||||
|
||||
@ -403,9 +417,10 @@ class Helper
|
||||
/**
|
||||
* Send response using standard PHP `header()` and `echo`.
|
||||
*
|
||||
* @api
|
||||
* @param Promise|ExecutionResult|ExecutionResult[] $result
|
||||
* @param bool $exitWhenDone
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function sendResponse($result, $exitWhenDone = false)
|
||||
{
|
||||
@ -425,9 +440,9 @@ class Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[]|\JsonSerializable $jsonSerializable
|
||||
* @param int $httpStatus
|
||||
* @param bool $exitWhenDone
|
||||
* @param mixed[]|JsonSerializable $jsonSerializable
|
||||
* @param int $httpStatus
|
||||
* @param bool $exitWhenDone
|
||||
*/
|
||||
public function emitResponse($jsonSerializable, $httpStatus, $exitWhenDone)
|
||||
{
|
||||
@ -450,6 +465,7 @@ class Helper
|
||||
|
||||
/**
|
||||
* @param ExecutionResult|mixed[] $result
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function resolveHttpStatus($result)
|
||||
@ -457,7 +473,7 @@ class Helper
|
||||
if (is_array($result) && isset($result[0])) {
|
||||
Utils::each(
|
||||
$result,
|
||||
function ($executionResult, $index) {
|
||||
static function ($executionResult, $index) {
|
||||
if (! $executionResult instanceof ExecutionResult) {
|
||||
throw new InvariantViolation(sprintf(
|
||||
'Expecting every entry of batched query result to be instance of %s but entry at position %d is %s',
|
||||
@ -490,9 +506,11 @@ class Helper
|
||||
/**
|
||||
* Converts PSR-7 request to OperationParams[]
|
||||
*
|
||||
* @api
|
||||
* @return OperationParams[]|OperationParams
|
||||
*
|
||||
* @throws RequestError
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function parsePsrRequest(ServerRequestInterface $request)
|
||||
{
|
||||
@ -541,9 +559,11 @@ class Helper
|
||||
/**
|
||||
* Converts query execution result to PSR-7 response
|
||||
*
|
||||
* @api
|
||||
* @param Promise|ExecutionResult|ExecutionResult[] $result
|
||||
*
|
||||
* @return Promise|ResponseInterface
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function toPsrResponse($result, ResponseInterface $response, StreamInterface $writableBodyStream)
|
||||
{
|
||||
|
@ -55,10 +55,12 @@ class OperationParams
|
||||
/**
|
||||
* Creates an instance from given array
|
||||
*
|
||||
* @api
|
||||
* @param mixed[] $params
|
||||
* @param bool $readonly
|
||||
*
|
||||
* @return OperationParams
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function create(array $params, $readonly = false)
|
||||
{
|
||||
@ -97,9 +99,11 @@ class OperationParams
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getOriginalInput($key)
|
||||
{
|
||||
@ -110,8 +114,9 @@ class OperationParams
|
||||
* Indicates that operation is executed in read-only context
|
||||
* (e.g. via HTTP GET request)
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function isReadOnly()
|
||||
{
|
||||
|
@ -4,9 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Server;
|
||||
|
||||
use Exception;
|
||||
use GraphQL\Error\ClientAware;
|
||||
|
||||
class RequestError extends \Exception implements ClientAware
|
||||
class RequestError extends Exception implements ClientAware
|
||||
{
|
||||
/**
|
||||
* Returns true when exception message is safe to be displayed to client
|
||||
|
@ -34,9 +34,11 @@ class ServerConfig
|
||||
* Converts an array of options to instance of ServerConfig
|
||||
* (or just returns empty config when array is not passed).
|
||||
*
|
||||
* @api
|
||||
* @param mixed[] $config
|
||||
*
|
||||
* @return ServerConfig
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function create(array $config = [])
|
||||
{
|
||||
@ -55,10 +57,10 @@ class ServerConfig
|
||||
/** @var Schema */
|
||||
private $schema;
|
||||
|
||||
/** @var mixed|\Closure */
|
||||
/** @var mixed|callable */
|
||||
private $context;
|
||||
|
||||
/** @var mixed|\Closure */
|
||||
/** @var mixed|callable */
|
||||
private $rootValue;
|
||||
|
||||
/** @var callable|null */
|
||||
@ -86,8 +88,9 @@ class ServerConfig
|
||||
private $persistentQueryLoader;
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setSchema(Schema $schema)
|
||||
{
|
||||
@ -97,9 +100,11 @@ class ServerConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @param mixed|\Closure $context
|
||||
* @param mixed|callable $context
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setContext($context)
|
||||
{
|
||||
@ -109,9 +114,11 @@ class ServerConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @param mixed|\Closure $rootValue
|
||||
* @param mixed|callable $rootValue
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setRootValue($rootValue)
|
||||
{
|
||||
@ -123,8 +130,9 @@ class ServerConfig
|
||||
/**
|
||||
* Expects function(Throwable $e) : array
|
||||
*
|
||||
* @api
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setErrorFormatter(callable $errorFormatter)
|
||||
{
|
||||
@ -136,8 +144,9 @@ class ServerConfig
|
||||
/**
|
||||
* Expects function(array $errors, callable $formatter) : array
|
||||
*
|
||||
* @api
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setErrorsHandler(callable $handler)
|
||||
{
|
||||
@ -149,9 +158,11 @@ class ServerConfig
|
||||
/**
|
||||
* Set validation rules for this server.
|
||||
*
|
||||
* @api
|
||||
* @param ValidationRule[]|callable $validationRules
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setValidationRules($validationRules)
|
||||
{
|
||||
@ -168,8 +179,9 @@ class ServerConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setFieldResolver(callable $fieldResolver)
|
||||
{
|
||||
@ -183,8 +195,9 @@ class ServerConfig
|
||||
*
|
||||
* This function must return query string or valid DocumentNode.
|
||||
*
|
||||
* @api
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setPersistentQueryLoader(callable $persistentQueryLoader)
|
||||
{
|
||||
@ -196,9 +209,11 @@ class ServerConfig
|
||||
/**
|
||||
* Set response debug flags. See GraphQL\Error\Debug class for a list of all available flags
|
||||
*
|
||||
* @api
|
||||
* @param bool|int $set
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDebug($set = true)
|
||||
{
|
||||
@ -210,9 +225,11 @@ class ServerConfig
|
||||
/**
|
||||
* Allow batching queries (disabled by default)
|
||||
*
|
||||
* @api
|
||||
* @param bool $enableBatching
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setQueryBatching($enableBatching)
|
||||
{
|
||||
@ -222,8 +239,9 @@ class ServerConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @return self
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setPromiseAdapter(PromiseAdapter $promiseAdapter)
|
||||
{
|
||||
|
@ -12,6 +12,7 @@ use GraphQL\Utils\Utils;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Throwable;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
@ -34,7 +35,6 @@ use function is_array;
|
||||
* $server->handleRequest();
|
||||
*
|
||||
* See [dedicated section in docs](executing-queries.md#using-server) for details.
|
||||
*
|
||||
*/
|
||||
class StandardServer
|
||||
{
|
||||
@ -49,10 +49,11 @@ class StandardServer
|
||||
* Useful when an exception is thrown somewhere outside of server execution context
|
||||
* (e.g. during schema instantiation).
|
||||
*
|
||||
* @param Throwable $error
|
||||
* @param bool $debug
|
||||
* @param bool $exitWhenDone
|
||||
*
|
||||
* @api
|
||||
* @param \Throwable $error
|
||||
* @param bool $debug
|
||||
* @param bool $exitWhenDone
|
||||
*/
|
||||
public static function send500Error($error, $debug = false, $exitWhenDone = false)
|
||||
{
|
||||
@ -66,8 +67,9 @@ class StandardServer
|
||||
/**
|
||||
* Creates new instance of a standard GraphQL HTTP server
|
||||
*
|
||||
* @api
|
||||
* @param ServerConfig|mixed[] $config
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
@ -91,9 +93,10 @@ class StandardServer
|
||||
* See `executeRequest()` if you prefer to emit response yourself
|
||||
* (e.g. using Response object of some framework)
|
||||
*
|
||||
* @api
|
||||
* @param OperationParams|OperationParams[] $parsedBody
|
||||
* @param bool $exitWhenDone
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function handleRequest($parsedBody = null, $exitWhenDone = false)
|
||||
{
|
||||
@ -111,10 +114,13 @@ class StandardServer
|
||||
*
|
||||
* PSR-7 compatible method executePsrRequest() does exactly this.
|
||||
*
|
||||
* @api
|
||||
* @param OperationParams|OperationParams[] $parsedBody
|
||||
*
|
||||
* @return ExecutionResult|ExecutionResult[]|Promise
|
||||
*
|
||||
* @throws InvariantViolation
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function executeRequest($parsedBody = null)
|
||||
{
|
||||
@ -135,8 +141,9 @@ class StandardServer
|
||||
* See `executePsrRequest()` if you prefer to create response yourself
|
||||
* (e.g. using specific JsonResponse instance of some framework).
|
||||
*
|
||||
* @api
|
||||
* @return ResponseInterface|Promise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function processPsrRequest(
|
||||
ServerRequestInterface $request,
|
||||
@ -151,8 +158,9 @@ class StandardServer
|
||||
* Executes GraphQL operation and returns execution result
|
||||
* (or promise when promise adapter is different from SyncPromiseAdapter)
|
||||
*
|
||||
* @api
|
||||
* @return ExecutionResult|ExecutionResult[]|Promise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function executePsrRequest(ServerRequestInterface $request)
|
||||
{
|
||||
@ -164,8 +172,9 @@ class StandardServer
|
||||
* Returns an instance of Server helper, which contains most of the actual logic for
|
||||
* parsing / validating / executing request (which could be re-used by other server implementations)
|
||||
*
|
||||
* @api
|
||||
* @return Helper
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getHelper()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user