mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-19 05:43:13 +03:00
New method "Executor::promiseToExecute()" which always returns promise (even for SyncPromiseAdapter)
This commit is contained in:
parent
0e2ac57515
commit
24ffd605f4
@ -112,21 +112,49 @@ class Executor
|
|||||||
PromiseAdapter $promiseAdapter = null
|
PromiseAdapter $promiseAdapter = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (null !== $variableValues) {
|
|
||||||
Utils::invariant(
|
|
||||||
is_array($variableValues) || $variableValues instanceof \ArrayAccess,
|
|
||||||
"Variable values are expected to be array or instance of ArrayAccess, got " . Utils::getVariableType($variableValues)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (null !== $operationName) {
|
|
||||||
Utils::invariant(
|
|
||||||
is_string($operationName),
|
|
||||||
"Operation name is supposed to be string, got " . Utils::getVariableType($operationName)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$promiseAdapter = $promiseAdapter ?: self::getPromiseAdapter();
|
$promiseAdapter = $promiseAdapter ?: self::getPromiseAdapter();
|
||||||
|
|
||||||
|
$result = self::promiseToExecute(
|
||||||
|
$promiseAdapter,
|
||||||
|
$schema,
|
||||||
|
$ast,
|
||||||
|
$rootValue,
|
||||||
|
$contextValue,
|
||||||
|
$variableValues,
|
||||||
|
$operationName,
|
||||||
|
$fieldResolver
|
||||||
|
);
|
||||||
|
|
||||||
|
// Wait for promised results when using sync promises
|
||||||
|
if ($promiseAdapter instanceof SyncPromiseAdapter) {
|
||||||
|
$result = $promiseAdapter->wait($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PromiseAdapter $promiseAdapter
|
||||||
|
* @param Schema $schema
|
||||||
|
* @param DocumentNode $ast
|
||||||
|
* @param null $rootValue
|
||||||
|
* @param null $contextValue
|
||||||
|
* @param null $variableValues
|
||||||
|
* @param null $operationName
|
||||||
|
* @param callable|null $fieldResolver
|
||||||
|
* @return Promise
|
||||||
|
*/
|
||||||
|
public static function promiseToExecute(
|
||||||
|
PromiseAdapter $promiseAdapter,
|
||||||
|
Schema $schema,
|
||||||
|
DocumentNode $ast,
|
||||||
|
$rootValue = null,
|
||||||
|
$contextValue = null,
|
||||||
|
$variableValues = null,
|
||||||
|
$operationName = null,
|
||||||
|
callable $fieldResolver = null
|
||||||
|
)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$exeContext = self::buildExecutionContext(
|
$exeContext = self::buildExecutionContext(
|
||||||
$schema,
|
$schema,
|
||||||
@ -139,21 +167,11 @@ class Executor
|
|||||||
$promiseAdapter
|
$promiseAdapter
|
||||||
);
|
);
|
||||||
} catch (Error $e) {
|
} catch (Error $e) {
|
||||||
if ($promiseAdapter instanceof SyncPromiseAdapter) {
|
|
||||||
return new ExecutionResult(null, [$e]);
|
|
||||||
} else {
|
|
||||||
return $promiseAdapter->createFulfilled(new ExecutionResult(null, [$e]));
|
return $promiseAdapter->createFulfilled(new ExecutionResult(null, [$e]));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$executor = new self($exeContext, $promiseAdapter);
|
$executor = new self($exeContext);
|
||||||
$result = $executor->executeQuery();
|
return $executor->executeQuery();
|
||||||
|
|
||||||
if ($result instanceof Promise && $promiseAdapter instanceof SyncPromiseAdapter) {
|
|
||||||
$result = $promiseAdapter->wait($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,6 +201,19 @@ class Executor
|
|||||||
PromiseAdapter $promiseAdapter = null
|
PromiseAdapter $promiseAdapter = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if (null !== $rawVariableValues) {
|
||||||
|
Utils::invariant(
|
||||||
|
is_array($rawVariableValues) || $rawVariableValues instanceof \ArrayAccess,
|
||||||
|
"Variable values are expected to be array or instance of ArrayAccess, got " . Utils::getVariableType($rawVariableValues)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (null !== $operationName) {
|
||||||
|
Utils::invariant(
|
||||||
|
is_string($operationName),
|
||||||
|
"Operation name is supposed to be string, got " . Utils::getVariableType($operationName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
$fragments = [];
|
$fragments = [];
|
||||||
$operation = null;
|
$operation = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user