From bc66034f400d76ac961035555102a93ae579a0f6 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sun, 23 Jun 2019 18:40:56 +0200 Subject: [PATCH 1/6] Rename parameters and private fields to match what they contain --- composer.json | 2 +- src/Executor/ExecutionContext.php | 8 ++--- src/Executor/ReferenceExecutor.php | 48 ++++++++++++++++-------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index b688618..5b63d0b 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "API" ], "require": { - "php": "^7.1||^8.0", + "php": "^7.1", "ext-json": "*", "ext-mbstring": "*" }, diff --git a/src/Executor/ExecutionContext.php b/src/Executor/ExecutionContext.php index 3de1a2e..13e675a 100644 --- a/src/Executor/ExecutionContext.php +++ b/src/Executor/ExecutionContext.php @@ -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) diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 6e35f7c..3f285a9 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -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 FieldNode[] $fieldNodes + * @param mixed[] $path + * @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 = []; From 65e4488ce80878dee2bc059837196c91bf2451b8 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sun, 23 Jun 2019 18:41:47 +0200 Subject: [PATCH 2/6] Reformat some comments --- src/Executor/ExecutionContext.php | 2 +- src/Executor/ReferenceExecutor.php | 2 +- src/Type/Definition/ResolveInfo.php | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Executor/ExecutionContext.php b/src/Executor/ExecutionContext.php index 13e675a..4e541f2 100644 --- a/src/Executor/ExecutionContext.php +++ b/src/Executor/ExecutionContext.php @@ -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 */ diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index 3f285a9..e4f83d5 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -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 diff --git a/src/Type/Definition/ResolveInfo.php b/src/Type/Definition/ResolveInfo.php index f2525de..8ab5486 100644 --- a/src/Type/Definition/ResolveInfo.php +++ b/src/Type/Definition/ResolveInfo.php @@ -20,7 +20,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 @@ -36,7 +36,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 @@ -44,7 +44,7 @@ class ResolveInfo public $returnType; /** - * Parent type of the field being resolved + * Parent type of the field being resolved. * * @api * @var ObjectType @@ -52,7 +52,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[][] @@ -60,7 +60,7 @@ class ResolveInfo public $path; /** - * Instance of a schema used for execution + * Instance of a schema used for execution. * * @api * @var Schema @@ -68,7 +68,7 @@ class ResolveInfo public $schema; /** - * AST of all fragments defined in query + * AST of all fragments defined in query. * * @api * @var FragmentDefinitionNode[] @@ -76,15 +76,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 @@ -92,7 +92,7 @@ class ResolveInfo public $operation; /** - * Array of variables passed to query execution + * Array of variables passed to query execution. * * @api * @var mixed[] @@ -136,7 +136,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{ From 9ca7bb6ea1f7dbd5d3f3ad8dc8a0a6474a2b3f70 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sun, 23 Jun 2019 18:42:25 +0200 Subject: [PATCH 3/6] Expand one letter variable names --- tests/Executor/DeferredFieldsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Executor/DeferredFieldsTest.php b/tests/Executor/DeferredFieldsTest.php index e68388c..439d117 100644 --- a/tests/Executor/DeferredFieldsTest.php +++ b/tests/Executor/DeferredFieldsTest.php @@ -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) { From 218e02a88ca0e51932526c2db2be0209918b1a5b Mon Sep 17 00:00:00 2001 From: spawnia Date: Sun, 23 Jun 2019 18:46:27 +0200 Subject: [PATCH 4/6] Revert composer.json changes --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5b63d0b..b688618 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "API" ], "require": { - "php": "^7.1", + "php": "^7.1||^8.0", "ext-json": "*", "ext-mbstring": "*" }, From a222cc9137580769caaa564f500f59472c518693 Mon Sep 17 00:00:00 2001 From: spawnia Date: Sun, 23 Jun 2019 21:08:49 +0200 Subject: [PATCH 5/6] Reword a comment --- src/Utils/MixedStore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/MixedStore.php b/src/Utils/MixedStore.php index 469abaa..8513fd5 100644 --- a/src/Utils/MixedStore.php +++ b/src/Utils/MixedStore.php @@ -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 { From 99453076b520f0ebdac7d392d2b35b053dd272cf Mon Sep 17 00:00:00 2001 From: spawnia Date: Sun, 30 Jun 2019 20:57:08 +0200 Subject: [PATCH 6/6] Remove &$ in phpdoc --- src/Executor/ReferenceExecutor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Executor/ReferenceExecutor.php b/src/Executor/ReferenceExecutor.php index e4f83d5..f2e85ff 100644 --- a/src/Executor/ReferenceExecutor.php +++ b/src/Executor/ReferenceExecutor.php @@ -932,7 +932,7 @@ class ReferenceExecutor implements ExecutorImplementation * * @param FieldNode[] $fieldNodes * @param mixed[] $path - * @param mixed[]|Traversable &$results + * @param mixed[]|Traversable $results * * @return mixed[]|Promise *