Merge pull request #508 from spawnia/consistency-and-clarity

Nonfunctional changes to improve consistency and clarity
This commit is contained in:
Vladimir Razuvaev 2019-07-01 12:52:21 +07:00 committed by GitHub
commit 9704baf422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 45 deletions

View File

@ -14,7 +14,7 @@ use GraphQL\Type\Schema;
* Data that must be available at all points during query execution.
*
* Namely, schema of the type system that is currently executing,
* and the fragments defined in the query document
* and the fragments defined in the query document.
*
* @internal
*/
@ -45,7 +45,7 @@ class ExecutionContext
public $errors;
/** @var PromiseAdapter */
public $promises;
public $promiseAdapter;
public function __construct(
$schema,
@ -53,7 +53,7 @@ class ExecutionContext
$root,
$contextValue,
$operation,
$variables,
$variableValues,
$errors,
$fieldResolver,
$promiseAdapter
@ -63,10 +63,10 @@ class ExecutionContext
$this->rootValue = $root;
$this->contextValue = $contextValue;
$this->operation = $operation;
$this->variableValues = $variables;
$this->variableValues = $variableValues;
$this->errors = $errors ?: [];
$this->fieldResolver = $fieldResolver;
$this->promises = $promiseAdapter;
$this->promiseAdapter = $promiseAdapter;
}
public function addError(Error $error)

View File

@ -199,7 +199,7 @@ class ReferenceExecutor implements ExecutorImplementation
public function doExecute() : Promise
{
// Return a Promise that will eventually resolve to the data described by
// The "Response" section of the GraphQL specification.
// the "Response" section of the GraphQL specification.
//
// If errors are encountered while executing a GraphQL field, only that
// field and its descendants will be omitted, and sibling fields will still
@ -212,7 +212,7 @@ class ReferenceExecutor implements ExecutorImplementation
// But for the "sync" case it is always fulfilled
return $this->isPromise($result)
? $result
: $this->exeContext->promises->createFulfilled($result);
: $this->exeContext->promiseAdapter->createFulfilled($result);
}
/**
@ -262,7 +262,7 @@ class ReferenceExecutor implements ExecutorImplementation
if ($error instanceof Error) {
$this->exeContext->addError($error);
return $this->exeContext->promises->createFulfilled(null);
return $this->exeContext->promiseAdapter->createFulfilled(null);
}
}
);
@ -574,6 +574,7 @@ class ReferenceExecutor implements ExecutorImplementation
/**
* This method looks up the field on the given type definition.
*
* It has special casing for the two introspection fields, __schema
* and __typename. __typename is special because it can always be
* queried as a field, even in situations where no other fields
@ -608,8 +609,8 @@ class ReferenceExecutor implements ExecutorImplementation
}
/**
* Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
* function. Returns the result of resolveFn or the abrupt-return Error object.
* Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField` function.
* Returns the result of resolveFn or the abrupt-return Error object.
*
* @param FieldDefinition $fieldDef
* @param FieldNode $fieldNode
@ -623,7 +624,7 @@ class ReferenceExecutor implements ExecutorImplementation
private function resolveOrError($fieldDef, $fieldNode, $resolveFn, $source, $context, $info)
{
try {
// Build hash of arguments from the field.arguments AST, using the
// Build a map of arguments from the field.arguments AST, using the
// variables scope to fulfill any variable references.
$args = Values::getArgumentValues(
$fieldDef,
@ -685,7 +686,7 @@ class ReferenceExecutor implements ExecutorImplementation
function ($error) use ($exeContext) {
$exeContext->addError($error);
return $this->exeContext->promises->createFulfilled(null);
return $this->exeContext->promiseAdapter->createFulfilled(null);
}
);
}
@ -732,7 +733,7 @@ class ReferenceExecutor implements ExecutorImplementation
return $promise->then(
null,
function ($error) use ($fieldNodes, $path) {
return $this->exeContext->promises->createRejected(Error::createLocatedError(
return $this->exeContext->promiseAdapter->createRejected(Error::createLocatedError(
$error,
$fieldNodes,
$path
@ -864,7 +865,7 @@ class ReferenceExecutor implements ExecutorImplementation
*/
private function isPromise($value)
{
return $value instanceof Promise || $this->exeContext->promises->isThenable($value);
return $value instanceof Promise || $this->exeContext->promiseAdapter->isThenable($value);
}
/**
@ -880,12 +881,12 @@ class ReferenceExecutor implements ExecutorImplementation
if ($value === null || $value instanceof Promise) {
return $value;
}
if ($this->exeContext->promises->isThenable($value)) {
$promise = $this->exeContext->promises->convertThenable($value);
if ($this->exeContext->promiseAdapter->isThenable($value)) {
$promise = $this->exeContext->promiseAdapter->convertThenable($value);
if (! $promise instanceof Promise) {
throw new InvariantViolation(sprintf(
'%s::convertThenable is expected to return instance of GraphQL\Executor\Promise\Promise, got: %s',
get_class($this->exeContext->promises),
get_class($this->exeContext->promiseAdapter),
Utils::printSafe($promise)
));
}
@ -927,28 +928,27 @@ class ReferenceExecutor implements ExecutorImplementation
}
/**
* Complete a list value by completing each item in the list with the
* inner type
* Complete a list value by completing each item in the list with the inner type.
*
* @param FieldNode[] $fieldNodes
* @param mixed[] $path
* @param mixed $result
* @param mixed[]|Traversable $results
*
* @return mixed[]|Promise
*
* @throws Exception
*/
private function completeListValue(ListOfType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
private function completeListValue(ListOfType $returnType, $fieldNodes, ResolveInfo $info, $path, &$results)
{
$itemType = $returnType->getWrappedType();
Utils::invariant(
is_array($result) || $result instanceof Traversable,
is_array($results) || $results instanceof Traversable,
'User Error: expected iterable, but did not find one for field ' . $info->parentType . '.' . $info->fieldName . '.'
);
$containsPromise = false;
$i = 0;
$completedItems = [];
foreach ($result as $item) {
foreach ($results as $item) {
$fieldPath = $path;
$fieldPath[] = $i++;
$info->path = $fieldPath;
@ -959,7 +959,9 @@ class ReferenceExecutor implements ExecutorImplementation
$completedItems[] = $completedItem;
}
return $containsPromise ? $this->exeContext->promises->all($completedItems) : $completedItems;
return $containsPromise
? $this->exeContext->promiseAdapter->all($completedItems)
: $completedItems;
}
/**
@ -1101,7 +1103,7 @@ class ReferenceExecutor implements ExecutorImplementation
}
}
if (! empty($promisedIsTypeOfResults)) {
return $this->exeContext->promises->all($promisedIsTypeOfResults)
return $this->exeContext->promiseAdapter->all($promisedIsTypeOfResults)
->then(static function ($isTypeOfResults) use ($possibleTypes) {
foreach ($isTypeOfResults as $index => $result) {
if ($result) {
@ -1187,7 +1189,7 @@ class ReferenceExecutor implements ExecutorImplementation
/**
* @param FieldNode[] $fieldNodes
* @param mixed[] $path
* @param mixed[] $result
* @param mixed $result
*
* @return mixed[]|Promise|stdClass
*
@ -1299,7 +1301,7 @@ class ReferenceExecutor implements ExecutorImplementation
{
$keys = array_keys($assoc);
$valuesAndPromises = array_values($assoc);
$promise = $this->exeContext->promises->all($valuesAndPromises);
$promise = $this->exeContext->promiseAdapter->all($valuesAndPromises);
return $promise->then(static function ($values) use ($keys) {
$resolvedResults = [];

View File

@ -21,7 +21,7 @@ use function array_merge_recursive;
class ResolveInfo
{
/**
* The name of the field being resolved
* The name of the field being resolved.
*
* @api
* @var string
@ -37,7 +37,7 @@ class ResolveInfo
public $fieldNodes = [];
/**
* Expected return type of the field being resolved
* Expected return type of the field being resolved.
*
* @api
* @var ScalarType|ObjectType|InterfaceType|UnionType|EnumType|ListOfType|NonNull
@ -45,7 +45,7 @@ class ResolveInfo
public $returnType;
/**
* Parent type of the field being resolved
* Parent type of the field being resolved.
*
* @api
* @var ObjectType
@ -53,7 +53,7 @@ class ResolveInfo
public $parentType;
/**
* Path to this field from the very root value
* Path to this field from the very root value.
*
* @api
* @var string[][]
@ -61,7 +61,7 @@ class ResolveInfo
public $path;
/**
* Instance of a schema used for execution
* Instance of a schema used for execution.
*
* @api
* @var Schema
@ -69,7 +69,7 @@ class ResolveInfo
public $schema;
/**
* AST of all fragments defined in query
* AST of all fragments defined in query.
*
* @api
* @var FragmentDefinitionNode[]
@ -77,15 +77,15 @@ class ResolveInfo
public $fragments = [];
/**
* Root value passed to query execution
* Root value passed to query execution.
*
* @api
* @var mixed|null
* @var mixed
*/
public $rootValue;
/**
* AST of operation definition node (query, mutation)
* AST of operation definition node (query, mutation).
*
* @api
* @var OperationDefinitionNode|null
@ -93,7 +93,7 @@ class ResolveInfo
public $operation;
/**
* Array of variables passed to query execution
* Array of variables passed to query execution.
*
* @api
* @var mixed[]
@ -137,7 +137,7 @@ class ResolveInfo
/**
* Helper method that returns names of all fields selected in query for
* $this->fieldName up to $depth levels
* $this->fieldName up to $depth levels.
*
* Example:
* query MyQuery{

View File

@ -21,7 +21,7 @@ use function is_string;
* Similar to PHP array, but allows any type of data to act as key (including arrays, objects, scalars)
*
* Note: unfortunately when storing array as key - access and modification is O(N)
* (yet this should be really rare case and should be avoided when possible)
* (yet this should rarely be the case and should be avoided when possible)
*/
class MixedStore implements ArrayAccess
{

View File

@ -401,7 +401,7 @@ class DeferredFieldsTest extends TestCase
return [
'sync' => [
'type' => Type::string(),
'resolve' => function ($v, $a, $c, ResolveInfo $info) {
'resolve' => function ($val, $args, $context, ResolveInfo $info) {
$this->paths[] = $info->path;
return 'sync';
@ -409,7 +409,7 @@ class DeferredFieldsTest extends TestCase
],
'deferred' => [
'type' => Type::string(),
'resolve' => function ($v, $a, $c, ResolveInfo $info) {
'resolve' => function ($val, $args, $context, ResolveInfo $info) {
$this->paths[] = $info->path;
return new Deferred(function () use ($info) {
@ -421,7 +421,7 @@ class DeferredFieldsTest extends TestCase
],
'nest' => [
'type' => $complexType,
'resolve' => function ($v, $a, $c, ResolveInfo $info) {
'resolve' => function ($val, $args, $context, ResolveInfo $info) {
$this->paths[] = $info->path;
return [];
@ -429,7 +429,7 @@ class DeferredFieldsTest extends TestCase
],
'deferredNest' => [
'type' => $complexType,
'resolve' => function ($v, $a, $c, ResolveInfo $info) {
'resolve' => function ($val, $args, $context, ResolveInfo $info) {
$this->paths[] = $info->path;
return new Deferred(function () use ($info) {