mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 12:56:05 +03:00
Fix CS in src/Executor
This commit is contained in:
parent
0063bd6c15
commit
bfebcd7bee
@ -6,6 +6,7 @@ namespace GraphQL\Executor;
|
|||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Error\FormattedError;
|
use GraphQL\Error\FormattedError;
|
||||||
|
use JsonSerializable;
|
||||||
use function array_map;
|
use function array_map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +17,7 @@ use function array_map;
|
|||||||
* Could be converted to [spec-compliant](https://facebook.github.io/graphql/#sec-Response-Format)
|
* Could be converted to [spec-compliant](https://facebook.github.io/graphql/#sec-Response-Format)
|
||||||
* serializable array using `toArray()`
|
* serializable array using `toArray()`
|
||||||
*/
|
*/
|
||||||
class ExecutionResult implements \JsonSerializable
|
class ExecutionResult implements JsonSerializable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Data collected from resolvers during query execution
|
* Data collected from resolvers during query execution
|
||||||
@ -77,8 +78,9 @@ class ExecutionResult implements \JsonSerializable
|
|||||||
* // ... other keys
|
* // ... other keys
|
||||||
* );
|
* );
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return self
|
* @return self
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function setErrorFormatter(callable $errorFormatter)
|
public function setErrorFormatter(callable $errorFormatter)
|
||||||
{
|
{
|
||||||
@ -97,8 +99,9 @@ class ExecutionResult implements \JsonSerializable
|
|||||||
* return array_map($formatter, $errors);
|
* return array_map($formatter, $errors);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return self
|
* @return self
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function setErrorsHandler(callable $handler)
|
public function setErrorsHandler(callable $handler)
|
||||||
{
|
{
|
||||||
@ -125,16 +128,18 @@ class ExecutionResult implements \JsonSerializable
|
|||||||
* $debug argument must be either bool (only adds "debugMessage" to result) or sum of flags from
|
* $debug argument must be either bool (only adds "debugMessage" to result) or sum of flags from
|
||||||
* GraphQL\Error\Debug
|
* GraphQL\Error\Debug
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param bool|int $debug
|
* @param bool|int $debug
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function toArray($debug = false)
|
public function toArray($debug = false)
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
if (! empty($this->errors)) {
|
if (! empty($this->errors)) {
|
||||||
$errorsHandler = $this->errorsHandler ?: function (array $errors, callable $formatter) {
|
$errorsHandler = $this->errorsHandler ?: static function (array $errors, callable $formatter) {
|
||||||
return array_map($formatter, $errors);
|
return array_map($formatter, $errors);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Executor;
|
namespace GraphQL\Executor;
|
||||||
|
|
||||||
|
use ArrayAccess;
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
|
use Exception;
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Error\InvariantViolation;
|
use GraphQL\Error\InvariantViolation;
|
||||||
use GraphQL\Error\Warning;
|
use GraphQL\Error\Warning;
|
||||||
@ -33,12 +35,18 @@ use GraphQL\Type\Introspection;
|
|||||||
use GraphQL\Type\Schema;
|
use GraphQL\Type\Schema;
|
||||||
use GraphQL\Utils\TypeInfo;
|
use GraphQL\Utils\TypeInfo;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
|
use RuntimeException;
|
||||||
|
use SplObjectStorage;
|
||||||
|
use stdClass;
|
||||||
|
use Throwable;
|
||||||
|
use Traversable;
|
||||||
use function array_keys;
|
use function array_keys;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function array_reduce;
|
use function array_reduce;
|
||||||
use function array_values;
|
use function array_values;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
|
use function is_callable;
|
||||||
use function is_object;
|
use function is_object;
|
||||||
use function is_string;
|
use function is_string;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
@ -52,7 +60,7 @@ class Executor
|
|||||||
private static $UNDEFINED;
|
private static $UNDEFINED;
|
||||||
|
|
||||||
/** @var callable|string[] */
|
/** @var callable|string[] */
|
||||||
private static $defaultFieldResolver = [__CLASS__, 'defaultFieldResolver'];
|
private static $defaultFieldResolver = [self::class, 'defaultFieldResolver'];
|
||||||
|
|
||||||
/** @var PromiseAdapter */
|
/** @var PromiseAdapter */
|
||||||
private static $promiseAdapter;
|
private static $promiseAdapter;
|
||||||
@ -60,7 +68,7 @@ class Executor
|
|||||||
/** @var ExecutionContext */
|
/** @var ExecutionContext */
|
||||||
private $exeContext;
|
private $exeContext;
|
||||||
|
|
||||||
/** @var \SplObjectStorage */
|
/** @var SplObjectStorage */
|
||||||
private $subFieldCache;
|
private $subFieldCache;
|
||||||
|
|
||||||
private function __construct(ExecutionContext $context)
|
private function __construct(ExecutionContext $context)
|
||||||
@ -70,13 +78,13 @@ class Executor
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->exeContext = $context;
|
$this->exeContext = $context;
|
||||||
$this->subFieldCache = new \SplObjectStorage();
|
$this->subFieldCache = new SplObjectStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom default resolve function
|
* Custom default resolve function
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function setDefaultFieldResolver(callable $fn)
|
public static function setDefaultFieldResolver(callable $fn)
|
||||||
{
|
{
|
||||||
@ -89,13 +97,14 @@ class Executor
|
|||||||
* Always returns ExecutionResult and never throws. All errors which occur during operation
|
* Always returns ExecutionResult and never throws. All errors which occur during operation
|
||||||
* execution are collected in `$result->errors`.
|
* execution are collected in `$result->errors`.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param mixed|null $rootValue
|
* @param mixed|null $rootValue
|
||||||
* @param mixed[]|null $contextValue
|
* @param mixed[]|null $contextValue
|
||||||
* @param mixed[]|\ArrayAccess|null $variableValues
|
* @param mixed[]|ArrayAccess|null $variableValues
|
||||||
* @param string|null $operationName
|
* @param string|null $operationName
|
||||||
*
|
*
|
||||||
* @return ExecutionResult|Promise
|
* @return ExecutionResult|Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function execute(
|
public static function execute(
|
||||||
Schema $schema,
|
Schema $schema,
|
||||||
@ -146,12 +155,14 @@ class Executor
|
|||||||
*
|
*
|
||||||
* Useful for async PHP platforms.
|
* Useful for async PHP platforms.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param mixed[]|null $rootValue
|
* @param mixed[]|null $rootValue
|
||||||
* @param mixed[]|null $contextValue
|
* @param mixed[]|null $contextValue
|
||||||
* @param mixed[]|null $variableValues
|
* @param mixed[]|null $variableValues
|
||||||
* @param string|null $operationName
|
* @param string|null $operationName
|
||||||
|
*
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public static function promiseToExecute(
|
public static function promiseToExecute(
|
||||||
PromiseAdapter $promiseAdapter,
|
PromiseAdapter $promiseAdapter,
|
||||||
@ -189,7 +200,7 @@ class Executor
|
|||||||
*
|
*
|
||||||
* @param mixed[] $rootValue
|
* @param mixed[] $rootValue
|
||||||
* @param mixed[] $contextValue
|
* @param mixed[] $contextValue
|
||||||
* @param mixed[]|\Traversable $rawVariableValues
|
* @param mixed[]|Traversable $rawVariableValues
|
||||||
* @param string|null $operationName
|
* @param string|null $operationName
|
||||||
*
|
*
|
||||||
* @return ExecutionContext|Error[]
|
* @return ExecutionContext|Error[]
|
||||||
@ -297,7 +308,8 @@ class Executor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed|null|Promise $data
|
* @param mixed|Promise|null $data
|
||||||
|
*
|
||||||
* @return ExecutionResult|Promise
|
* @return ExecutionResult|Promise
|
||||||
*/
|
*/
|
||||||
private function buildResponse($data)
|
private function buildResponse($data)
|
||||||
@ -317,12 +329,13 @@ class Executor
|
|||||||
* Implements the "Evaluating operations" section of the spec.
|
* Implements the "Evaluating operations" section of the spec.
|
||||||
*
|
*
|
||||||
* @param mixed[] $rootValue
|
* @param mixed[] $rootValue
|
||||||
* @return Promise|\stdClass|mixed[]
|
*
|
||||||
|
* @return Promise|stdClass|mixed[]
|
||||||
*/
|
*/
|
||||||
private function executeOperation(OperationDefinitionNode $operation, $rootValue)
|
private function executeOperation(OperationDefinitionNode $operation, $rootValue)
|
||||||
{
|
{
|
||||||
$type = $this->getOperationRootType($this->exeContext->schema, $operation);
|
$type = $this->getOperationRootType($this->exeContext->schema, $operation);
|
||||||
$fields = $this->collectFields($type, $operation->selectionSet, new \ArrayObject(), new \ArrayObject());
|
$fields = $this->collectFields($type, $operation->selectionSet, new ArrayObject(), new ArrayObject());
|
||||||
|
|
||||||
$path = [];
|
$path = [];
|
||||||
|
|
||||||
@ -357,6 +370,7 @@ class Executor
|
|||||||
* Extracts the root type of the operation from the schema.
|
* Extracts the root type of the operation from the schema.
|
||||||
*
|
*
|
||||||
* @return ObjectType
|
* @return ObjectType
|
||||||
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
*/
|
*/
|
||||||
private function getOperationRootType(Schema $schema, OperationDefinitionNode $operation)
|
private function getOperationRootType(Schema $schema, OperationDefinitionNode $operation)
|
||||||
@ -411,7 +425,7 @@ class Executor
|
|||||||
* @param ArrayObject $fields
|
* @param ArrayObject $fields
|
||||||
* @param ArrayObject $visitedFragmentNames
|
* @param ArrayObject $visitedFragmentNames
|
||||||
*
|
*
|
||||||
* @return \ArrayObject
|
* @return ArrayObject
|
||||||
*/
|
*/
|
||||||
private function collectFields(
|
private function collectFields(
|
||||||
ObjectType $runtimeType,
|
ObjectType $runtimeType,
|
||||||
@ -428,7 +442,7 @@ class Executor
|
|||||||
}
|
}
|
||||||
$name = self::getFieldEntryKey($selection);
|
$name = self::getFieldEntryKey($selection);
|
||||||
if (! isset($fields[$name])) {
|
if (! isset($fields[$name])) {
|
||||||
$fields[$name] = new \ArrayObject();
|
$fields[$name] = new ArrayObject();
|
||||||
}
|
}
|
||||||
$fields[$name][] = $selection;
|
$fields[$name][] = $selection;
|
||||||
break;
|
break;
|
||||||
@ -475,6 +489,7 @@ class Executor
|
|||||||
* directives, where @skip has higher precedence than @include.
|
* directives, where @skip has higher precedence than @include.
|
||||||
*
|
*
|
||||||
* @param FragmentSpreadNode|FieldNode|InlineFragmentNode $node
|
* @param FragmentSpreadNode|FieldNode|InlineFragmentNode $node
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function shouldIncludeNode($node)
|
private function shouldIncludeNode($node)
|
||||||
@ -521,6 +536,7 @@ class Executor
|
|||||||
* Determines if a fragment is applicable to the given type.
|
* Determines if a fragment is applicable to the given type.
|
||||||
*
|
*
|
||||||
* @param FragmentDefinitionNode|InlineFragmentNode $fragment
|
* @param FragmentDefinitionNode|InlineFragmentNode $fragment
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function doesFragmentConditionMatch(
|
private function doesFragmentConditionMatch(
|
||||||
@ -551,7 +567,8 @@ class Executor
|
|||||||
* @param mixed[] $sourceValue
|
* @param mixed[] $sourceValue
|
||||||
* @param mixed[] $path
|
* @param mixed[] $path
|
||||||
* @param ArrayObject $fields
|
* @param ArrayObject $fields
|
||||||
* @return Promise|\stdClass|mixed[]
|
*
|
||||||
|
* @return Promise|stdClass|mixed[]
|
||||||
*/
|
*/
|
||||||
private function executeFieldsSerially(ObjectType $parentType, $sourceValue, $path, $fields)
|
private function executeFieldsSerially(ObjectType $parentType, $sourceValue, $path, $fields)
|
||||||
{
|
{
|
||||||
@ -567,7 +584,7 @@ class Executor
|
|||||||
}
|
}
|
||||||
$promise = $this->getPromise($result);
|
$promise = $this->getPromise($result);
|
||||||
if ($promise) {
|
if ($promise) {
|
||||||
return $promise->then(function ($resolvedResult) use ($responseName, $results) {
|
return $promise->then(static function ($resolvedResult) use ($responseName, $results) {
|
||||||
$results[$responseName] = $resolvedResult;
|
$results[$responseName] = $resolvedResult;
|
||||||
return $results;
|
return $results;
|
||||||
});
|
});
|
||||||
@ -578,7 +595,7 @@ class Executor
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
if ($this->isPromise($result)) {
|
if ($this->isPromise($result)) {
|
||||||
return $result->then(function ($resolvedResults) {
|
return $result->then(static function ($resolvedResults) {
|
||||||
return self::fixResultsIfEmptyArray($resolvedResults);
|
return self::fixResultsIfEmptyArray($resolvedResults);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -595,7 +612,7 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param mixed[] $path
|
* @param mixed[] $path
|
||||||
*
|
*
|
||||||
* @return mixed[]|\Exception|mixed|null
|
* @return mixed[]|Exception|mixed|null
|
||||||
*/
|
*/
|
||||||
private function resolveField(ObjectType $parentType, $source, $fieldNodes, $path)
|
private function resolveField(ObjectType $parentType, $source, $fieldNodes, $path)
|
||||||
{
|
{
|
||||||
@ -705,7 +722,8 @@ class Executor
|
|||||||
* @param mixed $source
|
* @param mixed $source
|
||||||
* @param mixed $context
|
* @param mixed $context
|
||||||
* @param ResolveInfo $info
|
* @param ResolveInfo $info
|
||||||
* @return \Throwable|Promise|mixed
|
*
|
||||||
|
* @return Throwable|Promise|mixed
|
||||||
*/
|
*/
|
||||||
private function resolveOrError($fieldDef, $fieldNode, $resolveFn, $source, $context, $info)
|
private function resolveOrError($fieldDef, $fieldNode, $resolveFn, $source, $context, $info)
|
||||||
{
|
{
|
||||||
@ -719,9 +737,9 @@ class Executor
|
|||||||
);
|
);
|
||||||
|
|
||||||
return $resolveFn($source, $args, $context, $info);
|
return $resolveFn($source, $args, $context, $info);
|
||||||
} catch (\Exception $error) {
|
} catch (Exception $error) {
|
||||||
return $error;
|
return $error;
|
||||||
} catch (\Throwable $error) {
|
} catch (Throwable $error) {
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -733,6 +751,7 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param string[] $path
|
* @param string[] $path
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
|
*
|
||||||
* @return mixed[]|Promise|null
|
* @return mixed[]|Promise|null
|
||||||
*/
|
*/
|
||||||
private function completeValueCatchingError(
|
private function completeValueCatchingError(
|
||||||
@ -796,7 +815,9 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param string[] $path
|
* @param string[] $path
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
|
*
|
||||||
* @return mixed[]|mixed|Promise|null
|
* @return mixed[]|mixed|Promise|null
|
||||||
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
*/
|
*/
|
||||||
public function completeValueWithLocatedError(
|
public function completeValueWithLocatedError(
|
||||||
@ -829,9 +850,9 @@ class Executor
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $completed;
|
return $completed;
|
||||||
} catch (\Exception $error) {
|
} catch (Exception $error) {
|
||||||
throw Error::createLocatedError($error, $fieldNodes, $path);
|
throw Error::createLocatedError($error, $fieldNodes, $path);
|
||||||
} catch (\Throwable $error) {
|
} catch (Throwable $error) {
|
||||||
throw Error::createLocatedError($error, $fieldNodes, $path);
|
throw Error::createLocatedError($error, $fieldNodes, $path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -860,9 +881,11 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param string[] $path
|
* @param string[] $path
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
|
*
|
||||||
* @return mixed[]|mixed|Promise|null
|
* @return mixed[]|mixed|Promise|null
|
||||||
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
* @throws \Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
private function completeValue(
|
private function completeValue(
|
||||||
Type $returnType,
|
Type $returnType,
|
||||||
@ -880,7 +903,7 @@ class Executor
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result instanceof \Exception || $result instanceof \Throwable) {
|
if ($result instanceof Exception || $result instanceof Throwable) {
|
||||||
throw $result;
|
throw $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -949,11 +972,12 @@ class Executor
|
|||||||
return $this->completeObjectValue($returnType, $fieldNodes, $info, $path, $result);
|
return $this->completeObjectValue($returnType, $fieldNodes, $info, $path, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException(sprintf('Cannot complete value of unexpected type "%s".', $returnType));
|
throw new RuntimeException(sprintf('Cannot complete value of unexpected type "%s".', $returnType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isPromise($value)
|
private function isPromise($value)
|
||||||
@ -966,6 +990,7 @@ class Executor
|
|||||||
* otherwise returns null.
|
* otherwise returns null.
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
*
|
||||||
* @return Promise|null
|
* @return Promise|null
|
||||||
*/
|
*/
|
||||||
private function getPromise($value)
|
private function getPromise($value)
|
||||||
@ -998,14 +1023,15 @@ class Executor
|
|||||||
*
|
*
|
||||||
* @param mixed[] $values
|
* @param mixed[] $values
|
||||||
* @param Promise|mixed|null $initialValue
|
* @param Promise|mixed|null $initialValue
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
private function promiseReduce(array $values, \Closure $callback, $initialValue)
|
private function promiseReduce(array $values, callable $callback, $initialValue)
|
||||||
{
|
{
|
||||||
return array_reduce($values, function ($previous, $value) use ($callback) {
|
return array_reduce($values, function ($previous, $value) use ($callback) {
|
||||||
$promise = $this->getPromise($previous);
|
$promise = $this->getPromise($previous);
|
||||||
if ($promise) {
|
if ($promise) {
|
||||||
return $promise->then(function ($resolved) use ($callback, $value) {
|
return $promise->then(static function ($resolved) use ($callback, $value) {
|
||||||
return $callback($resolved, $value);
|
return $callback($resolved, $value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1020,14 +1046,16 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param mixed[] $path
|
* @param mixed[] $path
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
|
*
|
||||||
* @return mixed[]|Promise
|
* @return mixed[]|Promise
|
||||||
* @throws \Exception
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function completeListValue(ListOfType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
|
private function completeListValue(ListOfType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
|
||||||
{
|
{
|
||||||
$itemType = $returnType->getWrappedType();
|
$itemType = $returnType->getWrappedType();
|
||||||
Utils::invariant(
|
Utils::invariant(
|
||||||
is_array($result) || $result instanceof \Traversable,
|
is_array($result) || $result instanceof Traversable,
|
||||||
'User Error: expected iterable, but did not find one for field ' . $info->parentType . '.' . $info->fieldName . '.'
|
'User Error: expected iterable, but did not find one for field ' . $info->parentType . '.' . $info->fieldName . '.'
|
||||||
);
|
);
|
||||||
$containsPromise = false;
|
$containsPromise = false;
|
||||||
@ -1051,20 +1079,22 @@ class Executor
|
|||||||
* Complete a Scalar or Enum by serializing to a valid value, throwing if serialization is not possible.
|
* Complete a Scalar or Enum by serializing to a valid value, throwing if serialization is not possible.
|
||||||
*
|
*
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \Exception
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function completeLeafValue(LeafType $returnType, &$result)
|
private function completeLeafValue(LeafType $returnType, &$result)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $returnType->serialize($result);
|
return $returnType->serialize($result);
|
||||||
} catch (\Exception $error) {
|
} catch (Exception $error) {
|
||||||
throw new InvariantViolation(
|
throw new InvariantViolation(
|
||||||
'Expected a value of type "' . Utils::printSafe($returnType) . '" but received: ' . Utils::printSafe($result),
|
'Expected a value of type "' . Utils::printSafe($returnType) . '" but received: ' . Utils::printSafe($result),
|
||||||
0,
|
0,
|
||||||
$error
|
$error
|
||||||
);
|
);
|
||||||
} catch (\Throwable $error) {
|
} catch (Throwable $error) {
|
||||||
throw new InvariantViolation(
|
throw new InvariantViolation(
|
||||||
'Expected a value of type "' . Utils::printSafe($returnType) . '" but received: ' . Utils::printSafe($result),
|
'Expected a value of type "' . Utils::printSafe($returnType) . '" but received: ' . Utils::printSafe($result),
|
||||||
0,
|
0,
|
||||||
@ -1080,7 +1110,9 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param mixed[] $path
|
* @param mixed[] $path
|
||||||
* @param mixed[] $result
|
* @param mixed[] $result
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
*/
|
*/
|
||||||
private function completeAbstractValue(AbstractType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
|
private function completeAbstractValue(AbstractType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
|
||||||
@ -1142,6 +1174,7 @@ class Executor
|
|||||||
*
|
*
|
||||||
* @param mixed|null $value
|
* @param mixed|null $value
|
||||||
* @param mixed|null $context
|
* @param mixed|null $context
|
||||||
|
*
|
||||||
* @return ObjectType|Promise|null
|
* @return ObjectType|Promise|null
|
||||||
*/
|
*/
|
||||||
private function defaultTypeResolver($value, $context, ResolveInfo $info, AbstractType $abstractType)
|
private function defaultTypeResolver($value, $context, ResolveInfo $info, AbstractType $abstractType)
|
||||||
@ -1190,7 +1223,7 @@ class Executor
|
|||||||
|
|
||||||
if (! empty($promisedIsTypeOfResults)) {
|
if (! empty($promisedIsTypeOfResults)) {
|
||||||
return $this->exeContext->promises->all($promisedIsTypeOfResults)
|
return $this->exeContext->promises->all($promisedIsTypeOfResults)
|
||||||
->then(function ($isTypeOfResults) use ($possibleTypes) {
|
->then(static function ($isTypeOfResults) use ($possibleTypes) {
|
||||||
foreach ($isTypeOfResults as $index => $result) {
|
foreach ($isTypeOfResults as $index => $result) {
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $possibleTypes[$index];
|
return $possibleTypes[$index];
|
||||||
@ -1210,7 +1243,9 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param mixed[] $path
|
* @param mixed[] $path
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
* @return mixed[]|Promise|\stdClass
|
*
|
||||||
|
* @return mixed[]|Promise|stdClass
|
||||||
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
*/
|
*/
|
||||||
private function completeObjectValue(ObjectType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
|
private function completeObjectValue(ObjectType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
|
||||||
@ -1260,6 +1295,7 @@ class Executor
|
|||||||
/**
|
/**
|
||||||
* @param mixed[] $result
|
* @param mixed[] $result
|
||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
|
*
|
||||||
* @return Error
|
* @return Error
|
||||||
*/
|
*/
|
||||||
private function invalidReturnTypeError(
|
private function invalidReturnTypeError(
|
||||||
@ -1277,7 +1313,9 @@ class Executor
|
|||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param mixed[] $path
|
* @param mixed[] $path
|
||||||
* @param mixed[] $result
|
* @param mixed[] $result
|
||||||
* @return mixed[]|Promise|\stdClass
|
*
|
||||||
|
* @return mixed[]|Promise|stdClass
|
||||||
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
*/
|
*/
|
||||||
private function collectAndExecuteSubfields(
|
private function collectAndExecuteSubfields(
|
||||||
@ -1294,12 +1332,12 @@ class Executor
|
|||||||
private function collectSubFields(ObjectType $returnType, $fieldNodes) : ArrayObject
|
private function collectSubFields(ObjectType $returnType, $fieldNodes) : ArrayObject
|
||||||
{
|
{
|
||||||
if (! isset($this->subFieldCache[$returnType])) {
|
if (! isset($this->subFieldCache[$returnType])) {
|
||||||
$this->subFieldCache[$returnType] = new \SplObjectStorage();
|
$this->subFieldCache[$returnType] = new SplObjectStorage();
|
||||||
}
|
}
|
||||||
if (! isset($this->subFieldCache[$returnType][$fieldNodes])) {
|
if (! isset($this->subFieldCache[$returnType][$fieldNodes])) {
|
||||||
// Collect sub-fields to execute to complete this value.
|
// Collect sub-fields to execute to complete this value.
|
||||||
$subFieldNodes = new \ArrayObject();
|
$subFieldNodes = new ArrayObject();
|
||||||
$visitedFragmentNames = new \ArrayObject();
|
$visitedFragmentNames = new ArrayObject();
|
||||||
|
|
||||||
foreach ($fieldNodes as $fieldNode) {
|
foreach ($fieldNodes as $fieldNode) {
|
||||||
if (! isset($fieldNode->selectionSet)) {
|
if (! isset($fieldNode->selectionSet)) {
|
||||||
@ -1325,7 +1363,8 @@ class Executor
|
|||||||
* @param mixed|null $source
|
* @param mixed|null $source
|
||||||
* @param mixed[] $path
|
* @param mixed[] $path
|
||||||
* @param ArrayObject $fields
|
* @param ArrayObject $fields
|
||||||
* @return Promise|\stdClass|mixed[]
|
*
|
||||||
|
* @return Promise|stdClass|mixed[]
|
||||||
*/
|
*/
|
||||||
private function executeFields(ObjectType $parentType, $source, $path, $fields)
|
private function executeFields(ObjectType $parentType, $source, $path, $fields)
|
||||||
{
|
{
|
||||||
@ -1361,12 +1400,13 @@ class Executor
|
|||||||
* @see https://github.com/webonyx/graphql-php/issues/59
|
* @see https://github.com/webonyx/graphql-php/issues/59
|
||||||
*
|
*
|
||||||
* @param mixed[] $results
|
* @param mixed[] $results
|
||||||
* @return \stdClass|mixed[]
|
*
|
||||||
|
* @return stdClass|mixed[]
|
||||||
*/
|
*/
|
||||||
private static function fixResultsIfEmptyArray($results)
|
private static function fixResultsIfEmptyArray($results)
|
||||||
{
|
{
|
||||||
if ($results === []) {
|
if ($results === []) {
|
||||||
return new \stdClass();
|
return new stdClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
@ -1380,6 +1420,7 @@ class Executor
|
|||||||
* any promises.
|
* any promises.
|
||||||
*
|
*
|
||||||
* @param (string|Promise)[] $assoc
|
* @param (string|Promise)[] $assoc
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function promiseForAssocArray(array $assoc)
|
private function promiseForAssocArray(array $assoc)
|
||||||
@ -1389,7 +1430,7 @@ class Executor
|
|||||||
|
|
||||||
$promise = $this->exeContext->promises->all($valuesAndPromises);
|
$promise = $this->exeContext->promises->all($valuesAndPromises);
|
||||||
|
|
||||||
return $promise->then(function ($values) use ($keys) {
|
return $promise->then(static function ($values) use ($keys) {
|
||||||
$resolvedResults = [];
|
$resolvedResults = [];
|
||||||
foreach ($values as $i => $value) {
|
foreach ($values as $i => $value) {
|
||||||
$resolvedResults[$keys[$i]] = $value;
|
$resolvedResults[$keys[$i]] = $value;
|
||||||
@ -1403,6 +1444,7 @@ class Executor
|
|||||||
* @param string|ObjectType|null $runtimeTypeOrName
|
* @param string|ObjectType|null $runtimeTypeOrName
|
||||||
* @param FieldNode[] $fieldNodes
|
* @param FieldNode[] $fieldNodes
|
||||||
* @param mixed $result
|
* @param mixed $result
|
||||||
|
*
|
||||||
* @return ObjectType
|
* @return ObjectType
|
||||||
*/
|
*/
|
||||||
private function ensureValidRuntimeType(
|
private function ensureValidRuntimeType(
|
||||||
@ -1471,7 +1513,7 @@ class Executor
|
|||||||
$fieldName = $info->fieldName;
|
$fieldName = $info->fieldName;
|
||||||
$property = null;
|
$property = null;
|
||||||
|
|
||||||
if (is_array($source) || $source instanceof \ArrayAccess) {
|
if (is_array($source) || $source instanceof ArrayAccess) {
|
||||||
if (isset($source[$fieldName])) {
|
if (isset($source[$fieldName])) {
|
||||||
$property = $source[$fieldName];
|
$property = $source[$fieldName];
|
||||||
}
|
}
|
||||||
@ -1481,6 +1523,6 @@ class Executor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $property instanceof \Closure ? $property($source, $args, $context, $info) : $property;
|
return is_callable($property) ? $property($source, $args, $context, $info) : $property;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,12 +80,12 @@ class ReactPromiseAdapter implements PromiseAdapter
|
|||||||
// TODO: rework with generators when PHP minimum required version is changed to 5.5+
|
// TODO: rework with generators when PHP minimum required version is changed to 5.5+
|
||||||
$promisesOrValues = Utils::map(
|
$promisesOrValues = Utils::map(
|
||||||
$promisesOrValues,
|
$promisesOrValues,
|
||||||
function ($item) {
|
static function ($item) {
|
||||||
return $item instanceof Promise ? $item->adoptedPromise : $item;
|
return $item instanceof Promise ? $item->adoptedPromise : $item;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$promise = all($promisesOrValues)->then(function ($values) use ($promisesOrValues) {
|
$promise = all($promisesOrValues)->then(static function ($values) use ($promisesOrValues) {
|
||||||
$orderedResults = [];
|
$orderedResults = [];
|
||||||
|
|
||||||
foreach ($promisesOrValues as $key => $value) {
|
foreach ($promisesOrValues as $key => $value) {
|
||||||
|
@ -4,8 +4,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Executor\Promise\Adapter;
|
namespace GraphQL\Executor\Promise\Adapter;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Executor\ExecutionResult;
|
use GraphQL\Executor\ExecutionResult;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
|
use SplQueue;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use function is_object;
|
use function is_object;
|
||||||
use function method_exists;
|
use function method_exists;
|
||||||
@ -22,7 +24,7 @@ class SyncPromise
|
|||||||
const FULFILLED = 'fulfilled';
|
const FULFILLED = 'fulfilled';
|
||||||
const REJECTED = 'rejected';
|
const REJECTED = 'rejected';
|
||||||
|
|
||||||
/** @var \SplQueue */
|
/** @var SplQueue */
|
||||||
public static $queue;
|
public static $queue;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@ -33,6 +35,7 @@ class SyncPromise
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Promises created in `then` method of this promise and awaiting for resolution of this promise
|
* Promises created in `then` method of this promise and awaiting for resolution of this promise
|
||||||
|
*
|
||||||
* @var mixed[][]
|
* @var mixed[][]
|
||||||
*/
|
*/
|
||||||
private $waiting = [];
|
private $waiting = [];
|
||||||
@ -51,7 +54,7 @@ class SyncPromise
|
|||||||
switch ($this->state) {
|
switch ($this->state) {
|
||||||
case self::PENDING:
|
case self::PENDING:
|
||||||
if ($value === $this) {
|
if ($value === $this) {
|
||||||
throw new \Exception('Cannot resolve promise with self');
|
throw new Exception('Cannot resolve promise with self');
|
||||||
}
|
}
|
||||||
if (is_object($value) && method_exists($value, 'then')) {
|
if (is_object($value) && method_exists($value, 'then')) {
|
||||||
$value->then(
|
$value->then(
|
||||||
@ -72,11 +75,11 @@ class SyncPromise
|
|||||||
break;
|
break;
|
||||||
case self::FULFILLED:
|
case self::FULFILLED:
|
||||||
if ($this->result !== $value) {
|
if ($this->result !== $value) {
|
||||||
throw new \Exception('Cannot change value of fulfilled promise');
|
throw new Exception('Cannot change value of fulfilled promise');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::REJECTED:
|
case self::REJECTED:
|
||||||
throw new \Exception('Cannot resolve rejected promise');
|
throw new Exception('Cannot resolve rejected promise');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -84,8 +87,8 @@ class SyncPromise
|
|||||||
|
|
||||||
public function reject($reason)
|
public function reject($reason)
|
||||||
{
|
{
|
||||||
if (! $reason instanceof \Exception && ! $reason instanceof \Throwable) {
|
if (! $reason instanceof Exception && ! $reason instanceof Throwable) {
|
||||||
throw new \Exception('SyncPromise::reject() has to be called with an instance of \Throwable');
|
throw new Exception('SyncPromise::reject() has to be called with an instance of \Throwable');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($this->state) {
|
switch ($this->state) {
|
||||||
@ -96,11 +99,11 @@ class SyncPromise
|
|||||||
break;
|
break;
|
||||||
case self::REJECTED:
|
case self::REJECTED:
|
||||||
if ($reason !== $this->result) {
|
if ($reason !== $this->result) {
|
||||||
throw new \Exception('Cannot change rejection reason');
|
throw new Exception('Cannot change rejection reason');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::FULFILLED:
|
case self::FULFILLED:
|
||||||
throw new \Exception('Cannot reject fulfilled promise');
|
throw new Exception('Cannot reject fulfilled promise');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -116,14 +119,14 @@ class SyncPromise
|
|||||||
foreach ($this->waiting as $descriptor) {
|
foreach ($this->waiting as $descriptor) {
|
||||||
self::getQueue()->enqueue(function () use ($descriptor) {
|
self::getQueue()->enqueue(function () use ($descriptor) {
|
||||||
/** @var $promise self */
|
/** @var $promise self */
|
||||||
list($promise, $onFulfilled, $onRejected) = $descriptor;
|
[$promise, $onFulfilled, $onRejected] = $descriptor;
|
||||||
|
|
||||||
if ($this->state === self::FULFILLED) {
|
if ($this->state === self::FULFILLED) {
|
||||||
try {
|
try {
|
||||||
$promise->resolve($onFulfilled ? $onFulfilled($this->result) : $this->result);
|
$promise->resolve($onFulfilled ? $onFulfilled($this->result) : $this->result);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
$promise->reject($e);
|
$promise->reject($e);
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$promise->reject($e);
|
$promise->reject($e);
|
||||||
}
|
}
|
||||||
} elseif ($this->state === self::REJECTED) {
|
} elseif ($this->state === self::REJECTED) {
|
||||||
@ -133,9 +136,9 @@ class SyncPromise
|
|||||||
} else {
|
} else {
|
||||||
$promise->reject($this->result);
|
$promise->reject($this->result);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
$promise->reject($e);
|
$promise->reject($e);
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$promise->reject($e);
|
$promise->reject($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +149,7 @@ class SyncPromise
|
|||||||
|
|
||||||
public static function getQueue()
|
public static function getQueue()
|
||||||
{
|
{
|
||||||
return self::$queue ?: self::$queue = new \SplQueue();
|
return self::$queue ?: self::$queue = new SplQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
||||||
|
@ -4,12 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Executor\Promise\Adapter;
|
namespace GraphQL\Executor\Promise\Adapter;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use GraphQL\Deferred;
|
use GraphQL\Deferred;
|
||||||
use GraphQL\Error\InvariantViolation;
|
use GraphQL\Error\InvariantViolation;
|
||||||
use GraphQL\Executor\ExecutionResult;
|
use GraphQL\Executor\ExecutionResult;
|
||||||
use GraphQL\Executor\Promise\Promise;
|
use GraphQL\Executor\Promise\Promise;
|
||||||
use GraphQL\Executor\Promise\PromiseAdapter;
|
use GraphQL\Executor\Promise\PromiseAdapter;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
|
use Throwable;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,9 +69,9 @@ class SyncPromiseAdapter implements PromiseAdapter
|
|||||||
'reject',
|
'reject',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (Exception $e) {
|
||||||
$promise->reject($e);
|
$promise->reject($e);
|
||||||
} catch (\Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$promise->reject($e);
|
$promise->reject($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +113,7 @@ class SyncPromiseAdapter implements PromiseAdapter
|
|||||||
if ($promiseOrValue instanceof Promise) {
|
if ($promiseOrValue instanceof Promise) {
|
||||||
$result[$index] = null;
|
$result[$index] = null;
|
||||||
$promiseOrValue->then(
|
$promiseOrValue->then(
|
||||||
function ($value) use ($index, &$count, $total, &$result, $all) {
|
static function ($value) use ($index, &$count, $total, &$result, $all) {
|
||||||
$result[$index] = $value;
|
$result[$index] = $value;
|
||||||
$count++;
|
$count++;
|
||||||
if ($count < $total) {
|
if ($count < $total) {
|
||||||
@ -167,7 +169,6 @@ class SyncPromiseAdapter implements PromiseAdapter
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute just before starting to run promise completion
|
* Execute just before starting to run promise completion
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
protected function beforeWait(Promise $promise)
|
protected function beforeWait(Promise $promise)
|
||||||
{
|
{
|
||||||
@ -175,7 +176,6 @@ class SyncPromiseAdapter implements PromiseAdapter
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute while running promise completion
|
* Execute while running promise completion
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
protected function onWait(Promise $promise)
|
protected function onWait(Promise $promise)
|
||||||
{
|
{
|
||||||
|
@ -24,14 +24,13 @@ class Promise
|
|||||||
*/
|
*/
|
||||||
public function __construct($adoptedPromise, PromiseAdapter $adapter)
|
public function __construct($adoptedPromise, PromiseAdapter $adapter)
|
||||||
{
|
{
|
||||||
Utils::invariant(! $adoptedPromise instanceof self, 'Expecting promise from adapted system, got ' . __CLASS__);
|
Utils::invariant(! $adoptedPromise instanceof self, 'Expecting promise from adapted system, got ' . self::class);
|
||||||
|
|
||||||
$this->adapter = $adapter;
|
$this->adapter = $adapter;
|
||||||
$this->adoptedPromise = $adoptedPromise;
|
$this->adoptedPromise = $adoptedPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return Promise
|
* @return Promise
|
||||||
*/
|
*/
|
||||||
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
public function then(?callable $onFulfilled = null, ?callable $onRejected = null)
|
||||||
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace GraphQL\Executor\Promise;
|
namespace GraphQL\Executor\Promise;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a means for integration of async PHP platforms ([related docs](data-fetching.md#async-php))
|
* Provides a means for integration of async PHP platforms ([related docs](data-fetching.md#async-php))
|
||||||
*/
|
*/
|
||||||
@ -12,18 +14,22 @@ interface PromiseAdapter
|
|||||||
/**
|
/**
|
||||||
* Return true if the value is a promise or a deferred of the underlying platform
|
* Return true if the value is a promise or a deferred of the underlying platform
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function isThenable($value);
|
public function isThenable($value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts thenable of the underlying platform into GraphQL\Executor\Promise\Promise instance
|
* Converts thenable of the underlying platform into GraphQL\Executor\Promise\Promise instance
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param object $thenable
|
* @param object $thenable
|
||||||
|
*
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function convertThenable($thenable);
|
public function convertThenable($thenable);
|
||||||
|
|
||||||
@ -31,9 +37,9 @@ interface PromiseAdapter
|
|||||||
* Accepts our Promise wrapper, extracts adopted promise out of it and executes actual `then` logic described
|
* Accepts our Promise wrapper, extracts adopted promise out of it and executes actual `then` logic described
|
||||||
* in Promises/A+ specs. Then returns new wrapped instance of GraphQL\Executor\Promise\Promise.
|
* in Promises/A+ specs. Then returns new wrapped instance of GraphQL\Executor\Promise\Promise.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function then(Promise $promise, ?callable $onFulfilled = null, ?callable $onRejected = null);
|
public function then(Promise $promise, ?callable $onFulfilled = null, ?callable $onRejected = null);
|
||||||
|
|
||||||
@ -43,17 +49,20 @@ interface PromiseAdapter
|
|||||||
* Expected resolver signature:
|
* Expected resolver signature:
|
||||||
* function(callable $resolve, callable $reject)
|
* function(callable $resolve, callable $reject)
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function create(callable $resolver);
|
public function create(callable $resolver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a fulfilled Promise for a value if the value is not a promise.
|
* Creates a fulfilled Promise for a value if the value is not a promise.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
*
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function createFulfilled($value = null);
|
public function createFulfilled($value = null);
|
||||||
|
|
||||||
@ -61,9 +70,11 @@ interface PromiseAdapter
|
|||||||
* Creates a rejected promise for a reason if the reason is not a promise. If
|
* Creates a rejected promise for a reason if the reason is not a promise. If
|
||||||
* the provided reason is a promise, then it is returned as-is.
|
* the provided reason is a promise, then it is returned as-is.
|
||||||
*
|
*
|
||||||
* @api
|
* @param Throwable $reason
|
||||||
* @param \Throwable $reason
|
*
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function createRejected($reason);
|
public function createRejected($reason);
|
||||||
|
|
||||||
@ -71,9 +82,11 @@ interface PromiseAdapter
|
|||||||
* Given an array of promises (or values), returns a promise that is fulfilled when all the
|
* Given an array of promises (or values), returns a promise that is fulfilled when all the
|
||||||
* items in the array are fulfilled.
|
* items in the array are fulfilled.
|
||||||
*
|
*
|
||||||
* @api
|
|
||||||
* @param Promise[]|mixed[] $promisesOrValues Promises or values.
|
* @param Promise[]|mixed[] $promisesOrValues Promises or values.
|
||||||
|
*
|
||||||
* @return Promise
|
* @return Promise
|
||||||
|
*
|
||||||
|
* @api
|
||||||
*/
|
*/
|
||||||
public function all(array $promisesOrValues);
|
public function all(array $promisesOrValues);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ use GraphQL\Utils\AST;
|
|||||||
use GraphQL\Utils\TypeInfo;
|
use GraphQL\Utils\TypeInfo;
|
||||||
use GraphQL\Utils\Utils;
|
use GraphQL\Utils\Utils;
|
||||||
use GraphQL\Utils\Value;
|
use GraphQL\Utils\Value;
|
||||||
|
use stdClass;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use function array_key_exists;
|
use function array_key_exists;
|
||||||
use function array_map;
|
use function array_map;
|
||||||
@ -41,6 +42,7 @@ class Values
|
|||||||
*
|
*
|
||||||
* @param VariableDefinitionNode[] $varDefNodes
|
* @param VariableDefinitionNode[] $varDefNodes
|
||||||
* @param mixed[] $inputs
|
* @param mixed[] $inputs
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
*/
|
*/
|
||||||
public static function getVariableValues(Schema $schema, $varDefNodes, array $inputs)
|
public static function getVariableValues(Schema $schema, $varDefNodes, array $inputs)
|
||||||
@ -125,7 +127,7 @@ class Values
|
|||||||
if (isset($node->directives) && $node->directives instanceof NodeList) {
|
if (isset($node->directives) && $node->directives instanceof NodeList) {
|
||||||
$directiveNode = Utils::find(
|
$directiveNode = Utils::find(
|
||||||
$node->directives,
|
$node->directives,
|
||||||
function (DirectiveNode $directive) use ($directiveDef) {
|
static function (DirectiveNode $directive) use ($directiveDef) {
|
||||||
return $directive->name->value === $directiveDef->name;
|
return $directive->name->value === $directiveDef->name;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -145,7 +147,9 @@ class Values
|
|||||||
* @param FieldDefinition|Directive $def
|
* @param FieldDefinition|Directive $def
|
||||||
* @param FieldNode|DirectiveNode $node
|
* @param FieldNode|DirectiveNode $node
|
||||||
* @param mixed[] $variableValues
|
* @param mixed[] $variableValues
|
||||||
|
*
|
||||||
* @return mixed[]
|
* @return mixed[]
|
||||||
|
*
|
||||||
* @throws Error
|
* @throws Error
|
||||||
*/
|
*/
|
||||||
public static function getArgumentValues($def, $node, $variableValues = null)
|
public static function getArgumentValues($def, $node, $variableValues = null)
|
||||||
@ -162,7 +166,7 @@ class Values
|
|||||||
/** @var ArgumentNode[] $argNodeMap */
|
/** @var ArgumentNode[] $argNodeMap */
|
||||||
$argNodeMap = $argNodes ? Utils::keyMap(
|
$argNodeMap = $argNodes ? Utils::keyMap(
|
||||||
$argNodes,
|
$argNodes,
|
||||||
function (ArgumentNode $arg) {
|
static function (ArgumentNode $arg) {
|
||||||
return $arg->name->value;
|
return $arg->name->value;
|
||||||
}
|
}
|
||||||
) : [];
|
) : [];
|
||||||
@ -223,17 +227,20 @@ class Values
|
|||||||
* @deprecated as of 8.0 (Moved to \GraphQL\Utils\AST::valueFromAST)
|
* @deprecated as of 8.0 (Moved to \GraphQL\Utils\AST::valueFromAST)
|
||||||
*
|
*
|
||||||
* @param ValueNode $valueNode
|
* @param ValueNode $valueNode
|
||||||
* @param null $variables
|
* @param mixed[]|null $variables
|
||||||
* @return mixed[]|null|\stdClass
|
*
|
||||||
|
* @return mixed[]|stdClass|null
|
||||||
*/
|
*/
|
||||||
public static function valueFromAST($valueNode, InputType $type, $variables = null)
|
public static function valueFromAST($valueNode, InputType $type, ?array $variables = null)
|
||||||
{
|
{
|
||||||
return AST::valueFromAST($valueNode, $type, $variables);
|
return AST::valueFromAST($valueNode, $type, $variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated as of 0.12 (Use coerceValue() directly for richer information)
|
* @deprecated as of 0.12 (Use coerceValue() directly for richer information)
|
||||||
|
*
|
||||||
* @param mixed[] $value
|
* @param mixed[] $value
|
||||||
|
*
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public static function isValidPHPValue($value, InputType $type)
|
public static function isValidPHPValue($value, InputType $type)
|
||||||
@ -242,7 +249,7 @@ class Values
|
|||||||
|
|
||||||
return $errors
|
return $errors
|
||||||
? array_map(
|
? array_map(
|
||||||
function (Throwable $error) {
|
static function (Throwable $error) {
|
||||||
return $error->getMessage();
|
return $error->getMessage();
|
||||||
},
|
},
|
||||||
$errors
|
$errors
|
||||||
|
Loading…
Reference in New Issue
Block a user