From 0ab55ec0d93cc702ff9b5cafe4dfe3f1d70d03de Mon Sep 17 00:00:00 2001 From: vladar Date: Sat, 19 Nov 2016 06:47:55 +0700 Subject: [PATCH] Replaced "AST" with "Node" in variable names for better readability --- docs/type-system/scalar-types.md | 18 +-- .../01-blog/Blog/Type/Scalar/EmailType.php | 14 +-- src/Executor/Executor.php | 112 +++++++++--------- src/Executor/Values.php | 54 ++++----- src/GraphQL.php | 8 +- src/Type/Definition/CustomScalarType.php | 6 +- src/Type/Definition/LeafType.php | 4 +- src/Type/Definition/ResolveInfo.php | 36 ++++-- src/Utils/AST.php | 68 +++++------ src/Utils/TypeInfo.php | 24 ++-- src/Validator/DocumentValidator.php | 44 +++---- .../Rules/ArgumentsOfCorrectType.php | 8 +- .../Rules/DefaultValuesOfCorrectType.php | 6 +- .../Rules/OverlappingFieldsCanBeMerged.php | 12 +- .../Rules/ProvidedNonNullArguments.php | 36 +++--- src/Validator/Rules/QueryComplexity.php | 12 +- .../Rules/VariablesInAllowedPosition.php | 4 +- tests/ErrorTest.php | 12 +- tests/Executor/ExecutorTest.php | 6 +- tests/Executor/TestClasses.php | 4 +- tests/Executor/VariablesTest.php | 4 +- 21 files changed, 254 insertions(+), 238 deletions(-) diff --git a/docs/type-system/scalar-types.md b/docs/type-system/scalar-types.md index f688ab0..0c51a9f 100644 --- a/docs/type-system/scalar-types.md +++ b/docs/type-system/scalar-types.md @@ -90,21 +90,21 @@ class EmailType extends ScalarType * user(email: "user@example.com") * } * - * @param \GraphQL\Language\AST\Node $valueAST + * @param \GraphQL\Language\AST\Node $valueNode * @return string * @throws Error */ - public function parseLiteral($valueAST) + public function parseLiteral($valueNode) { // Note: throwing GraphQL\Error\Error vs \UnexpectedValueException to benefit from GraphQL // error location in query: - if (!$valueAST instanceof StringValueNode) { - throw new Error('Query error: Can only parse strings got: ' . $valueAST->kind, [$valueAST]); + if (!$valueNode instanceof StringValueNode) { + throw new Error('Query error: Can only parse strings got: ' . $valueNode->kind, [$valueNode]); } - if (!filter_var($valueAST->value, FILTER_VALIDATE_EMAIL)) { - throw new Error("Not a valid email", [$valueAST]); + if (!filter_var($valueNode->value, FILTER_VALIDATE_EMAIL)) { + throw new Error("Not a valid email", [$valueNode]); } - return $valueAST->value; + return $valueNode->value; } } ``` @@ -127,7 +127,7 @@ class EmailType implements DefinitionContainer 'name' => 'Email', 'serialize' => function($value) {/* See function body above */}, 'parseValue' => function($value) {/* See function body above */}, - 'parseLiteral' => function($valueAST) {/* See function body above */}, + 'parseLiteral' => function($valueNode) {/* See function body above */}, ])); } } @@ -143,6 +143,6 @@ $emailType = new CustomScalarType([ 'name' => 'Email', 'serialize' => function($value) {/* See function body above */}, 'parseValue' => function($value) {/* See function body above */}, - 'parseLiteral' => function($valueAST) {/* See function body above */}, + 'parseLiteral' => function($valueNode) {/* See function body above */}, ]); ``` diff --git a/examples/01-blog/Blog/Type/Scalar/EmailType.php b/examples/01-blog/Blog/Type/Scalar/EmailType.php index a620212..0eea0dd 100644 --- a/examples/01-blog/Blog/Type/Scalar/EmailType.php +++ b/examples/01-blog/Blog/Type/Scalar/EmailType.php @@ -53,20 +53,20 @@ class EmailType extends BaseType /** * Parses an externally provided literal value (hardcoded in GraphQL query) to use as an input * - * @param \GraphQL\Language\AST\Node $valueAST + * @param \GraphQL\Language\AST\Node $valueNode * @return string * @throws Error */ - public function parseLiteral($valueAST) + public function parseLiteral($valueNode) { // Note: throwing GraphQL\Error\Error vs \UnexpectedValueException to benefit from GraphQL // error location in query: - if (!$valueAST instanceof StringValueNode) { - throw new Error('Query error: Can only parse strings got: ' . $valueAST->kind, [$valueAST]); + if (!$valueNode instanceof StringValueNode) { + throw new Error('Query error: Can only parse strings got: ' . $valueNode->kind, [$valueNode]); } - if (!filter_var($valueAST->value, FILTER_VALIDATE_EMAIL)) { - throw new Error("Not a valid email", [$valueAST]); + if (!filter_var($valueNode->value, FILTER_VALIDATE_EMAIL)) { + throw new Error("Not a valid email", [$valueNode]); } - return $valueAST->value; + return $valueNode->value; } } diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index cbe02f5..a4472f8 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -106,7 +106,7 @@ class Executor */ private static function buildExecutionContext( Schema $schema, - DocumentNode $documentAst, + DocumentNode $documentNode, $rootValue, $contextValue, $rawVariableValues, @@ -117,7 +117,7 @@ class Executor $fragments = []; $operation = null; - foreach ($documentAst->definitions as $definition) { + foreach ($documentNode->definitions as $definition) { switch ($definition->kind) { case NodeType::OPERATION_DEFINITION: if (!$operationName && $operation) { @@ -222,10 +222,10 @@ class Executor private static function executeFieldsSerially(ExecutionContext $exeContext, ObjectType $parentType, $sourceValue, $path, $fields) { $results = []; - foreach ($fields as $responseName => $fieldASTs) { + foreach ($fields as $responseName => $fieldNodes) { $fieldPath = $path; $fieldPath[] = $responseName; - $result = self::resolveField($exeContext, $parentType, $sourceValue, $fieldASTs, $fieldPath); + $result = self::resolveField($exeContext, $parentType, $sourceValue, $fieldNodes, $fieldPath); if ($result !== self::$UNDEFINED) { // Undefined means that field is not defined in schema @@ -329,29 +329,29 @@ class Executor $skipDirective = Directive::skipDirective(); $includeDirective = Directive::includeDirective(); - /** @var \GraphQL\Language\AST\DirectiveNode $skipAST */ - $skipAST = $directives + /** @var \GraphQL\Language\AST\DirectiveNode $skipNode */ + $skipNode = $directives ? Utils::find($directives, function(\GraphQL\Language\AST\DirectiveNode $directive) use ($skipDirective) { return $directive->name->value === $skipDirective->name; }) : null; - if ($skipAST) { - $argValues = Values::getArgumentValues($skipDirective, $skipAST, $exeContext->variableValues); + if ($skipNode) { + $argValues = Values::getArgumentValues($skipDirective, $skipNode, $exeContext->variableValues); if (isset($argValues['if']) && $argValues['if'] === true) { return false; } } - /** @var \GraphQL\Language\AST\DirectiveNode $includeAST */ - $includeAST = $directives + /** @var \GraphQL\Language\AST\DirectiveNode $includeNode */ + $includeNode = $directives ? Utils::find($directives, function(\GraphQL\Language\AST\DirectiveNode $directive) use ($includeDirective) { return $directive->name->value === $includeDirective->name; }) : null; - if ($includeAST) { - $argValues = Values::getArgumentValues($includeDirective, $includeAST, $exeContext->variableValues); + if ($includeNode) { + $argValues = Values::getArgumentValues($includeDirective, $includeNode, $exeContext->variableValues); if (isset($argValues['if']) && $argValues['if'] === false) { return false; } @@ -365,13 +365,13 @@ class Executor */ private static function doesFragmentConditionMatch(ExecutionContext $exeContext,/* FragmentDefinitionNode | InlineFragmentNode*/ $fragment, ObjectType $type) { - $typeConditionAST = $fragment->typeCondition; + $typeConditionNode = $fragment->typeCondition; - if (!$typeConditionAST) { + if (!$typeConditionNode) { return true; } - $conditionalType = Utils\TypeInfo::typeFromAST($exeContext->schema, $typeConditionAST); + $conditionalType = Utils\TypeInfo::typeFromAST($exeContext->schema, $typeConditionNode); if ($conditionalType === $type) { return true; } @@ -395,11 +395,11 @@ class Executor * then calls completeValue to complete promises, serialize scalars, or execute * the sub-selection-set for objects. */ - private static function resolveField(ExecutionContext $exeContext, ObjectType $parentType, $source, $fieldASTs, $path) + private static function resolveField(ExecutionContext $exeContext, ObjectType $parentType, $source, $fieldNodes, $path) { - $fieldAST = $fieldASTs[0]; + $fieldNode = $fieldNodes[0]; - $fieldName = $fieldAST->name->value; + $fieldName = $fieldNode->name->value; $fieldDef = self::getFieldDef($exeContext->schema, $parentType, $fieldName); @@ -413,7 +413,7 @@ class Executor // information about the current execution state. $info = new ResolveInfo([ 'fieldName' => $fieldName, - 'fieldASTs' => $fieldASTs, + 'fieldNodes' => $fieldNodes, 'returnType' => $returnType, 'parentType' => $parentType, 'path' => $path, @@ -443,7 +443,7 @@ class Executor $result = self::resolveOrError( $exeContext, $fieldDef, - $fieldAST, + $fieldNode, $resolveFn, $source, $context, @@ -453,7 +453,7 @@ class Executor $result = self::completeValueCatchingError( $exeContext, $returnType, - $fieldASTs, + $fieldNodes, $info, $path, $result @@ -468,21 +468,21 @@ class Executor * * @param ExecutionContext $exeContext * @param FieldDefinition $fieldDef - * @param FieldNode $fieldAST + * @param FieldNode $fieldNode * @param callable $resolveFn * @param mixed $source * @param mixed $context * @param ResolveInfo $info * @return \Exception|mixed */ - private static function resolveOrError($exeContext, $fieldDef, $fieldAST, $resolveFn, $source, $context, $info) + private static function resolveOrError($exeContext, $fieldDef, $fieldNode, $resolveFn, $source, $context, $info) { try { // Build hash of arguments from the field.arguments AST, using the // variables scope to fulfill any variable references. $args = Values::getArgumentValues( $fieldDef, - $fieldAST, + $fieldNode, $exeContext->variableValues ); @@ -498,7 +498,7 @@ class Executor * * @param ExecutionContext $exeContext * @param Type $returnType - * @param $fieldASTs + * @param $fieldNodes * @param ResolveInfo $info * @param $path * @param $result @@ -507,7 +507,7 @@ class Executor private static function completeValueCatchingError( ExecutionContext $exeContext, Type $returnType, - $fieldASTs, + $fieldNodes, ResolveInfo $info, $path, $result @@ -519,7 +519,7 @@ class Executor return self::completeValueWithLocatedError( $exeContext, $returnType, - $fieldASTs, + $fieldNodes, $info, $path, $result @@ -532,7 +532,7 @@ class Executor return self::completeValueWithLocatedError( $exeContext, $returnType, - $fieldASTs, + $fieldNodes, $info, $path, $result @@ -552,7 +552,7 @@ class Executor * * @param ExecutionContext $exeContext * @param Type $returnType - * @param $fieldASTs + * @param $fieldNodes * @param ResolveInfo $info * @param $path * @param $result @@ -562,7 +562,7 @@ class Executor static function completeValueWithLocatedError( ExecutionContext $exeContext, Type $returnType, - $fieldASTs, + $fieldNodes, ResolveInfo $info, $path, $result @@ -572,13 +572,13 @@ class Executor return self::completeValue( $exeContext, $returnType, - $fieldASTs, + $fieldNodes, $info, $path, $result ); } catch (\Exception $error) { - throw Error::createLocatedError($error, $fieldASTs, $path); + throw Error::createLocatedError($error, $fieldNodes, $path); } } @@ -605,7 +605,7 @@ class Executor * * @param ExecutionContext $exeContext * @param Type $returnType - * @param FieldNode[] $fieldASTs + * @param FieldNode[] $fieldNodes * @param ResolveInfo $info * @param array $path * @param $result @@ -616,7 +616,7 @@ class Executor private static function completeValue( ExecutionContext $exeContext, Type $returnType, - $fieldASTs, + $fieldNodes, ResolveInfo $info, $path, &$result @@ -632,7 +632,7 @@ class Executor $completed = self::completeValue( $exeContext, $returnType->getWrappedType(), - $fieldASTs, + $fieldNodes, $info, $path, $result @@ -652,7 +652,7 @@ class Executor // If field type is List, complete each item in the list with the inner type if ($returnType instanceof ListOfType) { - return self::completeListValue($exeContext, $returnType, $fieldASTs, $info, $path, $result); + return self::completeListValue($exeContext, $returnType, $fieldNodes, $info, $path, $result); } // If field type is Scalar or Enum, serialize to a valid value, returning @@ -662,12 +662,12 @@ class Executor } if ($returnType instanceof AbstractType) { - return self::completeAbstractValue($exeContext, $returnType, $fieldASTs, $info, $path, $result); + return self::completeAbstractValue($exeContext, $returnType, $fieldNodes, $info, $path, $result); } // Field type must be Object, Interface or Union and expect sub-selections. if ($returnType instanceof ObjectType) { - return self::completeObjectValue($exeContext, $returnType, $fieldASTs, $info, $path, $result); + return self::completeObjectValue($exeContext, $returnType, $fieldNodes, $info, $path, $result); } throw new \RuntimeException("Cannot complete value of unexpected type \"{$returnType}\"."); @@ -734,14 +734,14 @@ class Executor * * @param ExecutionContext $exeContext * @param AbstractType $returnType - * @param $fieldASTs + * @param $fieldNodes * @param ResolveInfo $info * @param array $path * @param $result * @return mixed * @throws Error */ - private static function completeAbstractValue(ExecutionContext $exeContext, AbstractType $returnType, $fieldASTs, ResolveInfo $info, $path, &$result) + private static function completeAbstractValue(ExecutionContext $exeContext, AbstractType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result) { $runtimeType = $returnType->resolveType($result, $exeContext->contextValue, $info); @@ -764,17 +764,17 @@ class Executor "Abstract type {$returnType} must resolve to an Object type at runtime " . "for field {$info->parentType}.{$info->fieldName} with value \"" . print_r($result, true) . "\"," . "received \"$runtimeType\".", - $fieldASTs + $fieldNodes ); } if (!$exeContext->schema->isPossibleType($returnType, $runtimeType)) { throw new Error( "Runtime Object type \"$runtimeType\" is not a possible type for \"$returnType\".", - $fieldASTs + $fieldNodes ); } - return self::completeObjectValue($exeContext, $runtimeType, $fieldASTs, $info, $path, $result); + return self::completeObjectValue($exeContext, $runtimeType, $fieldNodes, $info, $path, $result); } /** @@ -783,14 +783,14 @@ class Executor * * @param ExecutionContext $exeContext * @param ListOfType $returnType - * @param $fieldASTs + * @param $fieldNodes * @param ResolveInfo $info * @param array $path * @param $result * @return array * @throws \Exception */ - private static function completeListValue(ExecutionContext $exeContext, ListOfType $returnType, $fieldASTs, ResolveInfo $info, $path, &$result) + private static function completeListValue(ExecutionContext $exeContext, ListOfType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result) { $itemType = $returnType->getWrappedType(); Utils::invariant( @@ -803,7 +803,7 @@ class Executor foreach ($result as $item) { $fieldPath = $path; $fieldPath[] = $i++; - $tmp[] = self::completeValueCatchingError($exeContext, $itemType, $fieldASTs, $info, $fieldPath, $item); + $tmp[] = self::completeValueCatchingError($exeContext, $itemType, $fieldNodes, $info, $fieldPath, $item); } return $tmp; } @@ -834,14 +834,14 @@ class Executor * * @param ExecutionContext $exeContext * @param ObjectType $returnType - * @param $fieldASTs + * @param $fieldNodes * @param ResolveInfo $info * @param array $path * @param $result * @return array * @throws Error */ - private static function completeObjectValue(ExecutionContext $exeContext, ObjectType $returnType, $fieldASTs, ResolveInfo $info, $path, &$result) + private static function completeObjectValue(ExecutionContext $exeContext, ObjectType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result) { // If there is an isTypeOf predicate function, call it with the // current result. If isTypeOf returns false, then raise an error rather @@ -849,27 +849,27 @@ class Executor if (false === $returnType->isTypeOf($result, $exeContext->contextValue, $info)) { throw new Error( "Expected value of type $returnType but got: " . Utils::getVariableType($result), - $fieldASTs + $fieldNodes ); } // Collect sub-fields to execute to complete this value. - $subFieldASTs = new \ArrayObject(); + $subFieldNodes = new \ArrayObject(); $visitedFragmentNames = new \ArrayObject(); - foreach ($fieldASTs as $fieldAST) { - if (isset($fieldAST->selectionSet)) { - $subFieldASTs = self::collectFields( + foreach ($fieldNodes as $fieldNode) { + if (isset($fieldNode->selectionSet)) { + $subFieldNodes = self::collectFields( $exeContext, $returnType, - $fieldAST->selectionSet, - $subFieldASTs, + $fieldNode->selectionSet, + $subFieldNodes, $visitedFragmentNames ); } } - return self::executeFields($exeContext, $returnType, $result, $path, $subFieldASTs); + return self::executeFields($exeContext, $returnType, $result, $path, $subFieldNodes); } /** diff --git a/src/Executor/Values.php b/src/Executor/Values.php index 6f9ef2b..a5d4b4a 100644 --- a/src/Executor/Values.php +++ b/src/Executor/Values.php @@ -32,28 +32,28 @@ class Values * to match the variable definitions, a Error will be thrown. * * @param Schema $schema - * @param VariableDefinitionNode[] $definitionASTs + * @param VariableDefinitionNode[] $definitionNodes * @param array $inputs * @return array * @throws Error */ - public static function getVariableValues(Schema $schema, $definitionASTs, array $inputs) + public static function getVariableValues(Schema $schema, $definitionNodes, array $inputs) { $coercedValues = []; - foreach ($definitionASTs as $definitionAST) { - $varName = $definitionAST->variable->name->value; - $varType = Utils\TypeInfo::typeFromAST($schema, $definitionAST->type); + foreach ($definitionNodes as $definitionNode) { + $varName = $definitionNode->variable->name->value; + $varType = Utils\TypeInfo::typeFromAST($schema, $definitionNode->type); if (!Type::isInputType($varType)) { throw new Error( 'Variable "$'.$varName.'" expected value of type ' . - '"' . Printer::doPrint($definitionAST->type) . '" which cannot be used as an input type.', - [$definitionAST->type] + '"' . Printer::doPrint($definitionNode->type) . '" which cannot be used as an input type.', + [$definitionNode->type] ); } if (!array_key_exists($varName, $inputs)) { - $defaultValue = $definitionAST->defaultValue; + $defaultValue = $definitionNode->defaultValue; if ($defaultValue) { $coercedValues[$varName] = Utils\AST::valueFromAST($defaultValue, $varType); } @@ -61,7 +61,7 @@ class Values throw new Error( 'Variable "$'.$varName .'" of required type ' . '"'. Utils::printSafe($varType) . '" was not provided.', - [$definitionAST] + [$definitionNode] ); } } else { @@ -72,7 +72,7 @@ class Values throw new Error( 'Variable "$' . $varName . '" got invalid value ' . json_encode($value) . '.' . $message, - [$definitionAST] + [$definitionNode] ); } @@ -97,26 +97,26 @@ class Values public static function getArgumentValues($def, $node, $variableValues) { $argDefs = $def->args; - $argASTs = $node->arguments; + $argNodes = $node->arguments; - if (!$argDefs || null === $argASTs) { + if (!$argDefs || null === $argNodes) { return []; } $coercedValues = []; $undefined = Utils::undefined(); - /** @var ArgumentNode[] $argASTMap */ - $argASTMap = $argASTs ? Utils::keyMap($argASTs, function (ArgumentNode $arg) { + /** @var ArgumentNode[] $argNodeMap */ + $argNodeMap = $argNodes ? Utils::keyMap($argNodes, function (ArgumentNode $arg) { return $arg->name->value; }) : []; foreach ($argDefs as $argDef) { $name = $argDef->name; $argType = $argDef->getType(); - $argumentAST = isset($argASTMap[$name]) ? $argASTMap[$name] : null; + $argumentNode = isset($argNodeMap[$name]) ? $argNodeMap[$name] : null; - if (!$argumentAST) { + if (!$argumentNode) { if ($argDef->defaultValueExists()) { $coercedValues[$name] = $argDef->defaultValue; } else if ($argType instanceof NonNull) { @@ -126,8 +126,8 @@ class Values [$node] ); } - } else if ($argumentAST->value instanceof VariableNode) { - $variableName = $argumentAST->value->name->value; + } else if ($argumentNode->value instanceof VariableNode) { + $variableName = $argumentNode->value->name->value; if ($variableValues && array_key_exists($variableName, $variableValues)) { // Note: this does not check that this variable value is correct. @@ -141,18 +141,18 @@ class Values 'Argument "' . $name . '" of required type "' . Utils::printSafe($argType) . '" was ' . 'provided the variable "$' . $variableName . '" which was not provided ' . 'a runtime value.', - [ $argumentAST->value ] + [ $argumentNode->value ] ); } } else { - $valueAST = $argumentAST->value; - $coercedValue = Utils\AST::valueFromAST($valueAST, $argType, $variableValues); + $valueNode = $argumentNode->value; + $coercedValue = Utils\AST::valueFromAST($valueNode, $argType, $variableValues); if ($coercedValue === $undefined) { - $errors = DocumentValidator::isValidLiteralValue($argType, $valueAST); + $errors = DocumentValidator::isValidLiteralValue($argType, $valueNode); $message = !empty($errors) ? ("\n" . implode("\n", $errors)) : ''; throw new Error( - 'Argument "' . $name . '" got invalid value ' . Printer::doPrint($valueAST) . '.' . $message, - [ $argumentAST->value ] + 'Argument "' . $name . '" got invalid value ' . Printer::doPrint($valueNode) . '.' . $message, + [ $argumentNode->value ] ); } $coercedValues[$name] = $coercedValue; @@ -164,14 +164,14 @@ class Values /** * @deprecated Moved to Utils\AST::valueFromAST * - * @param $valueAST + * @param $valueNode * @param InputType $type * @param null $variables * @return array|null|\stdClass */ - public static function valueFromAST($valueAST, InputType $type, $variables = null) + public static function valueFromAST($valueNode, InputType $type, $variables = null) { - return Utils\AST::valueFromAST($valueAST, $type, $variables); + return Utils\AST::valueFromAST($valueNode, $type, $variables); } /** diff --git a/src/GraphQL.php b/src/GraphQL.php index 9e3a0f8..6b4b6b5 100644 --- a/src/GraphQL.php +++ b/src/GraphQL.php @@ -38,22 +38,22 @@ class GraphQL { try { if ($requestString instanceof DocumentNode) { - $documentAST = $requestString; + $documentNode = $requestString; } else { $source = new Source($requestString ?: '', 'GraphQL request'); - $documentAST = Parser::parse($source); + $documentNode = Parser::parse($source); } /** @var QueryComplexity $queryComplexity */ $queryComplexity = DocumentValidator::getRule('QueryComplexity'); $queryComplexity->setRawVariableValues($variableValues); - $validationErrors = DocumentValidator::validate($schema, $documentAST); + $validationErrors = DocumentValidator::validate($schema, $documentNode); if (!empty($validationErrors)) { return new ExecutionResult(null, $validationErrors); } else { - return Executor::execute($schema, $documentAST, $rootValue, $contextValue, $variableValues, $operationName); + return Executor::execute($schema, $documentNode, $rootValue, $contextValue, $variableValues, $operationName); } } catch (Error $e) { return new ExecutionResult(null, [$e]); diff --git a/src/Type/Definition/CustomScalarType.php b/src/Type/Definition/CustomScalarType.php index 4879785..d425c88 100644 --- a/src/Type/Definition/CustomScalarType.php +++ b/src/Type/Definition/CustomScalarType.php @@ -42,11 +42,11 @@ class CustomScalarType extends ScalarType } /** - * @param $valueAST + * @param $valueNode * @return mixed */ - public function parseLiteral(/* GraphQL\Language\AST\ValueNode */ $valueAST) + public function parseLiteral(/* GraphQL\Language\AST\ValueNode */ $valueNode) { - return call_user_func($this->config['parseLiteral'], $valueAST); + return call_user_func($this->config['parseLiteral'], $valueNode); } } diff --git a/src/Type/Definition/LeafType.php b/src/Type/Definition/LeafType.php index e813628..0c61a02 100644 --- a/src/Type/Definition/LeafType.php +++ b/src/Type/Definition/LeafType.php @@ -27,8 +27,8 @@ interface LeafType /** * Parses an externally provided literal value (hardcoded in GraphQL query) to use as an input * - * @param \GraphQL\Language\AST\Node $valueAST + * @param \GraphQL\Language\AST\Node $valueNode * @return mixed */ - public function parseLiteral($valueAST); + public function parseLiteral($valueNode); } diff --git a/src/Type/Definition/ResolveInfo.php b/src/Type/Definition/ResolveInfo.php index fae95bb..03ca726 100644 --- a/src/Type/Definition/ResolveInfo.php +++ b/src/Type/Definition/ResolveInfo.php @@ -1,6 +1,7 @@ fieldASTs as $fieldAST) { - $fields = array_merge_recursive($fields, $this->foldSelectionSet($fieldAST->selectionSet, $depth)); + /** @var FieldNode $fieldNode */ + foreach ($this->fieldNodes as $fieldNode) { + $fields = array_merge_recursive($fields, $this->foldSelectionSet($fieldNode->selectionSet, $depth)); } return $fields; @@ -118,13 +125,13 @@ class ResolveInfo { $fields = []; - foreach ($selectionSet->selections as $selectionAST) { - if ($selectionAST instanceof FieldNode) { - $fields[$selectionAST->name->value] = $descend > 0 && !empty($selectionAST->selectionSet) - ? $this->foldSelectionSet($selectionAST->selectionSet, $descend - 1) + foreach ($selectionSet->selections as $selectionNode) { + if ($selectionNode instanceof FieldNode) { + $fields[$selectionNode->name->value] = $descend > 0 && !empty($selectionNode->selectionSet) + ? $this->foldSelectionSet($selectionNode->selectionSet, $descend - 1) : true; - } else if ($selectionAST instanceof FragmentSpreadNode) { - $spreadName = $selectionAST->name->value; + } else if ($selectionNode instanceof FragmentSpreadNode) { + $spreadName = $selectionNode->name->value; if (isset($this->fragments[$spreadName])) { /** @var FragmentDefinitionNode $fragment */ $fragment = $this->fragments[$spreadName]; @@ -135,4 +142,13 @@ class ResolveInfo return $fields; } + + public function __get($name) + { + if ('fieldASTs' === $name) { + trigger_error('Property ' . __CLASS__ . '->fieldASTs was renamed to ' . __CLASS__ . '->fieldNodes', E_USER_DEPRECATED); + return $this->fieldNodes; + } + throw new InvariantViolation("Undefined property '$name' in class " . __CLASS__); + } } diff --git a/src/Utils/AST.php b/src/Utils/AST.php index 23e310b..3b793fd 100644 --- a/src/Utils/AST.php +++ b/src/Utils/AST.php @@ -71,14 +71,14 @@ class AST if ($type instanceof ListOfType) { $itemType = $type->getWrappedType(); if (is_array($value) || ($value instanceof \Traversable)) { - $valuesASTs = []; + $valuesNodes = []; foreach ($value as $item) { - $itemAST = self::astFromValue($item, $itemType); - if ($itemAST) { - $valuesASTs[] = $itemAST; + $itemNode = self::astFromValue($item, $itemType); + if ($itemNode) { + $valuesNodes[] = $itemNode; } } - return new ListValueNode(['values' => $valuesASTs]); + return new ListValueNode(['values' => $valuesNodes]); } return self::astFromValue($value, $itemType); } @@ -92,7 +92,7 @@ class AST return null; } $fields = $type->getFields(); - $fieldASTs = []; + $fieldNodes = []; foreach ($fields as $fieldName => $field) { if ($isArrayLike) { $fieldValue = isset($value[$fieldName]) ? $value[$fieldName] : null; @@ -117,14 +117,14 @@ class AST $fieldNode = self::astFromValue($fieldValue, $field->getType()); if ($fieldNode) { - $fieldASTs[] = new ObjectFieldNode([ + $fieldNodes[] = new ObjectFieldNode([ 'name' => new NameNode(['value' => $fieldName]), 'value' => $fieldNode ]); } } } - return new ObjectValueNode(['fields' => $fieldASTs]); + return new ObjectValueNode(['fields' => $fieldNodes]); } // Since value is an internally represented value, it must be serialized @@ -193,37 +193,37 @@ class AST * | Enum Value | Mixed | * | Null Value | stdClass | instance of NullValue::getNullValue() * - * @param $valueAST + * @param $valueNode * @param InputType $type * @param null $variables * @return array|null|\stdClass * @throws \Exception */ - public static function valueFromAST($valueAST, InputType $type, $variables = null) + public static function valueFromAST($valueNode, InputType $type, $variables = null) { $undefined = Utils::undefined(); - if (!$valueAST) { + if (!$valueNode) { // When there is no AST, then there is also no value. // Importantly, this is different from returning the GraphQL null value. return $undefined; } if ($type instanceof NonNull) { - if ($valueAST instanceof NullValueNode) { + if ($valueNode instanceof NullValueNode) { // Invalid: intentionally return no value. return $undefined; } - return self::valueFromAST($valueAST, $type->getWrappedType(), $variables); + return self::valueFromAST($valueNode, $type->getWrappedType(), $variables); } - if ($valueAST instanceof NullValueNode) { + if ($valueNode instanceof NullValueNode) { // This is explicitly returning the value null. return null; } - if ($valueAST instanceof VariableNode) { - $variableName = $valueAST->name->value; + if ($valueNode instanceof VariableNode) { + $variableName = $valueNode->name->value; if (!$variables || !array_key_exists($variableName, $variables)) { // No valid return value. @@ -238,11 +238,11 @@ class AST if ($type instanceof ListOfType) { $itemType = $type->getWrappedType(); - if ($valueAST instanceof ListValueNode) { + if ($valueNode instanceof ListValueNode) { $coercedValues = []; - $itemASTs = $valueAST->values; - foreach ($itemASTs as $itemAST) { - if (self::isMissingVariable($itemAST, $variables)) { + $itemNodes = $valueNode->values; + foreach ($itemNodes as $itemNode) { + if (self::isMissingVariable($itemNode, $variables)) { // If an array contains a missing variable, it is either coerced to // null or if the item type is non-null, it considered invalid. if ($itemType instanceof NonNull) { @@ -251,7 +251,7 @@ class AST } $coercedValues[] = null; } else { - $itemValue = self::valueFromAST($itemAST, $itemType, $variables); + $itemValue = self::valueFromAST($itemNode, $itemType, $variables); if ($undefined === $itemValue) { // Invalid: intentionally return no value. return $undefined; @@ -261,7 +261,7 @@ class AST } return $coercedValues; } - $coercedValue = self::valueFromAST($valueAST, $itemType, $variables); + $coercedValue = self::valueFromAST($valueNode, $itemType, $variables); if ($undefined === $coercedValue) { // Invalid: intentionally return no value. return $undefined; @@ -270,20 +270,20 @@ class AST } if ($type instanceof InputObjectType) { - if (!$valueAST instanceof ObjectValueNode) { + if (!$valueNode instanceof ObjectValueNode) { // Invalid: intentionally return no value. return $undefined; } $coercedObj = []; $fields = $type->getFields(); - $fieldASTs = Utils::keyMap($valueAST->fields, function($field) {return $field->name->value;}); + $fieldNodes = Utils::keyMap($valueNode->fields, function($field) {return $field->name->value;}); foreach ($fields as $field) { - /** @var ValueNode $fieldAST */ + /** @var ValueNode $fieldNode */ $fieldName = $field->name; - $fieldAST = isset($fieldASTs[$fieldName]) ? $fieldASTs[$fieldName] : null; + $fieldNode = isset($fieldNodes[$fieldName]) ? $fieldNodes[$fieldName] : null; - if (!$fieldAST || self::isMissingVariable($fieldAST->value, $variables)) { + if (!$fieldNode || self::isMissingVariable($fieldNode->value, $variables)) { if ($field->defaultValueExists()) { $coercedObj[$fieldName] = $field->defaultValue; } else if ($field->getType() instanceof NonNull) { @@ -293,7 +293,7 @@ class AST continue ; } - $fieldValue = self::valueFromAST($fieldAST ? $fieldAST->value : null, $field->getType(), $variables); + $fieldValue = self::valueFromAST($fieldNode ? $fieldNode->value : null, $field->getType(), $variables); if ($undefined === $fieldValue) { // Invalid: intentionally return no value. @@ -305,7 +305,7 @@ class AST } if ($type instanceof LeafType) { - $parsed = $type->parseLiteral($valueAST); + $parsed = $type->parseLiteral($valueNode); if (null === $parsed) { // null represent a failure to parse correctly, @@ -321,15 +321,15 @@ class AST /** - * Returns true if the provided valueAST is a variable which is not defined + * Returns true if the provided valueNode is a variable which is not defined * in the set of variables. - * @param $valueAST + * @param $valueNode * @param $variables * @return bool */ - private static function isMissingVariable($valueAST, $variables) + private static function isMissingVariable($valueNode, $variables) { - return $valueAST instanceof VariableNode && - (!$variables || !array_key_exists($valueAST->name->value, $variables)); + return $valueNode instanceof VariableNode && + (!$variables || !array_key_exists($valueNode->name->value, $variables)); } } diff --git a/src/Utils/TypeInfo.php b/src/Utils/TypeInfo.php index 7910062..c4eda75 100644 --- a/src/Utils/TypeInfo.php +++ b/src/Utils/TypeInfo.php @@ -143,23 +143,23 @@ class TypeInfo /** * @param Schema $schema - * @param $inputTypeAst + * @param $inputTypeAST * @return Type * @throws \Exception */ - public static function typeFromAST(Schema $schema, $inputTypeAst) + public static function typeFromAST(Schema $schema, $inputTypeNode) { - if ($inputTypeAst instanceof ListTypeNode) { - $innerType = self::typeFromAST($schema, $inputTypeAst->type); + if ($inputTypeNode instanceof ListTypeNode) { + $innerType = self::typeFromAST($schema, $inputTypeNode->type); return $innerType ? new ListOfType($innerType) : null; } - if ($inputTypeAst instanceof NonNullTypeNode) { - $innerType = self::typeFromAST($schema, $inputTypeAst->type); + if ($inputTypeNode instanceof NonNullTypeNode) { + $innerType = self::typeFromAST($schema, $inputTypeNode->type); return $innerType ? new NonNull($innerType) : null; } - Utils::invariant($inputTypeAst && $inputTypeAst instanceof NamedTypeNode, 'Must be a named type'); - return $schema->getType($inputTypeAst->name->value); + Utils::invariant($inputTypeNode && $inputTypeNode instanceof NamedTypeNode, 'Must be a named type'); + return $schema->getType($inputTypeNode->name->value); } /** @@ -169,9 +169,9 @@ class TypeInfo * * @return FieldDefinition */ - static private function getFieldDefinition(Schema $schema, Type $parentType, FieldNode $fieldAST) + static private function getFieldDefinition(Schema $schema, Type $parentType, FieldNode $fieldNode) { - $name = $fieldAST->name->value; + $name = $fieldNode->name->value; $schemaMeta = Introspection::schemaMetaFieldDef(); if ($name === $schemaMeta->name && $schema->getQueryType() === $parentType) { return $schemaMeta; @@ -348,8 +348,8 @@ class TypeInfo case NodeType::INLINE_FRAGMENT: case NodeType::FRAGMENT_DEFINITION: - $typeConditionAST = $node->typeCondition; - $outputType = $typeConditionAST ? self::typeFromAST($schema, $typeConditionAST) : $this->getType(); + $typeConditionNode = $node->typeCondition; + $outputType = $typeConditionNode ? self::typeFromAST($schema, $typeConditionNode) : $this->getType(); $this->typeStack[] = $outputType; // push break; diff --git a/src/Validator/DocumentValidator.php b/src/Validator/DocumentValidator.php index c40b168..1fbacac 100644 --- a/src/Validator/DocumentValidator.php +++ b/src/Validator/DocumentValidator.php @@ -153,33 +153,33 @@ class DocumentValidator * * @return array */ - public static function isValidLiteralValue(Type $type, $valueAST) + public static function isValidLiteralValue(Type $type, $valueNode) { // A value must be provided if the type is non-null. if ($type instanceof NonNull) { - if (!$valueAST || $valueAST instanceof NullValueNode) { + if (!$valueNode || $valueNode instanceof NullValueNode) { return [ 'Expected "' . Utils::printSafe($type) . '", found null.' ]; } - return static::isValidLiteralValue($type->getWrappedType(), $valueAST); + return static::isValidLiteralValue($type->getWrappedType(), $valueNode); } - if (!$valueAST || $valueAST instanceof NullValueNode) { + if (!$valueNode || $valueNode instanceof NullValueNode) { return []; } // This function only tests literals, and assumes variables will provide // values of the correct type. - if ($valueAST instanceof VariableNode) { + if ($valueNode instanceof VariableNode) { return []; } // Lists accept a non-list value as a list of one. if ($type instanceof ListOfType) { $itemType = $type->getWrappedType(); - if ($valueAST instanceof ListValueNode) { + if ($valueNode instanceof ListValueNode) { $errors = []; - foreach($valueAST->values as $index => $itemAST) { - $tmp = static::isValidLiteralValue($itemType, $itemAST); + foreach($valueNode->values as $index => $itemNode) { + $tmp = static::isValidLiteralValue($itemType, $itemNode); if ($tmp) { $errors = array_merge($errors, Utils::map($tmp, function($error) use ($index) { @@ -189,13 +189,13 @@ class DocumentValidator } return $errors; } else { - return static::isValidLiteralValue($itemType, $valueAST); + return static::isValidLiteralValue($itemType, $valueNode); } } // Input objects check each defined field and look for undefined fields. if ($type instanceof InputObjectType) { - if ($valueAST->kind !== NodeType::OBJECT) { + if ($valueNode->kind !== NodeType::OBJECT) { return [ "Expected \"{$type->name}\", found not an object." ]; } @@ -203,20 +203,20 @@ class DocumentValidator $errors = []; // Ensure every provided field is defined. - $fieldASTs = $valueAST->fields; + $fieldNodes = $valueNode->fields; - foreach ($fieldASTs as $providedFieldAST) { - if (empty($fields[$providedFieldAST->name->value])) { - $errors[] = "In field \"{$providedFieldAST->name->value}\": Unknown field."; + foreach ($fieldNodes as $providedFieldNode) { + if (empty($fields[$providedFieldNode->name->value])) { + $errors[] = "In field \"{$providedFieldNode->name->value}\": Unknown field."; } } // Ensure every defined field is valid. - $fieldASTMap = Utils::keyMap($fieldASTs, function($fieldAST) {return $fieldAST->name->value;}); + $fieldNodeMap = Utils::keyMap($fieldNodes, function($fieldNode) {return $fieldNode->name->value;}); foreach ($fields as $fieldName => $field) { $result = static::isValidLiteralValue( $field->getType(), - isset($fieldASTMap[$fieldName]) ? $fieldASTMap[$fieldName]->value : null + isset($fieldNodeMap[$fieldName]) ? $fieldNodeMap[$fieldName]->value : null ); if ($result) { $errors = array_merge($errors, Utils::map($result, function($error) use ($fieldName) { @@ -231,10 +231,10 @@ class DocumentValidator if ($type instanceof LeafType) { // Scalar/Enum input checks to ensure the type can parse the value to // a non-null value. - $parseResult = $type->parseLiteral($valueAST); + $parseResult = $type->parseLiteral($valueNode); if (null === $parseResult) { - $printed = Printer::doPrint($valueAST); + $printed = Printer::doPrint($valueNode); return [ "Expected type \"{$type->name}\", found $printed." ]; } @@ -250,18 +250,18 @@ class DocumentValidator * * @param Schema $schema * @param TypeInfo $typeInfo - * @param DocumentNode $documentAST + * @param DocumentNode $documentNode * @param array $rules * @return array */ - public static function visitUsingRules(Schema $schema, TypeInfo $typeInfo, DocumentNode $documentAST, array $rules) + public static function visitUsingRules(Schema $schema, TypeInfo $typeInfo, DocumentNode $documentNode, array $rules) { - $context = new ValidationContext($schema, $documentAST, $typeInfo); + $context = new ValidationContext($schema, $documentNode, $typeInfo); $visitors = []; foreach ($rules as $rule) { $visitors[] = $rule($context); } - Visitor::visit($documentAST, Visitor::visitWithTypeInfo($typeInfo, Visitor::visitInParallel($visitors))); + Visitor::visit($documentNode, Visitor::visitWithTypeInfo($typeInfo, Visitor::visitInParallel($visitors))); return $context->getErrors(); } } diff --git a/src/Validator/Rules/ArgumentsOfCorrectType.php b/src/Validator/Rules/ArgumentsOfCorrectType.php index 81058cd..ec03d92 100644 --- a/src/Validator/Rules/ArgumentsOfCorrectType.php +++ b/src/Validator/Rules/ArgumentsOfCorrectType.php @@ -26,15 +26,15 @@ class ArgumentsOfCorrectType public function __invoke(ValidationContext $context) { return [ - NodeType::ARGUMENT => function(ArgumentNode $argAST) use ($context) { + NodeType::ARGUMENT => function(ArgumentNode $argNode) use ($context) { $argDef = $context->getArgument(); if ($argDef) { - $errors = DocumentValidator::isValidLiteralValue($argDef->getType(), $argAST->value); + $errors = DocumentValidator::isValidLiteralValue($argDef->getType(), $argNode->value); if (!empty($errors)) { $context->reportError(new Error( - self::badValueMessage($argAST->name->value, $argDef->getType(), Printer::doPrint($argAST->value), $errors), - [$argAST->value] + self::badValueMessage($argNode->name->value, $argDef->getType(), Printer::doPrint($argNode->value), $errors), + [$argNode->value] )); } } diff --git a/src/Validator/Rules/DefaultValuesOfCorrectType.php b/src/Validator/Rules/DefaultValuesOfCorrectType.php index e54a599..cb12431 100644 --- a/src/Validator/Rules/DefaultValuesOfCorrectType.php +++ b/src/Validator/Rules/DefaultValuesOfCorrectType.php @@ -30,9 +30,9 @@ class DefaultValuesOfCorrectType public function __invoke(ValidationContext $context) { return [ - NodeType::VARIABLE_DEFINITION => function(VariableDefinitionNode $varDefAST) use ($context) { - $name = $varDefAST->variable->name->value; - $defaultValue = $varDefAST->defaultValue; + NodeType::VARIABLE_DEFINITION => function(VariableDefinitionNode $varDefNode) use ($context) { + $name = $varDefNode->variable->name->value; + $defaultValue = $varDefNode->defaultValue; $type = $context->getInputType(); if ($type instanceof NonNull && $defaultValue) { diff --git a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php index 22d29ee..5470335 100644 --- a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php +++ b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php @@ -58,7 +58,7 @@ class OverlappingFieldsCanBeMerged // Note: we validate on the reverse traversal so deeper conflicts will be // caught first, for clearer error messages. 'leave' => function(SelectionSetNode $selectionSet) use ($context) { - $fieldMap = $this->collectFieldASTsAndDefs( + $fieldMap = $this->collectFieldNodesAndDefs( $context, $context->getParentType(), $selectionSet @@ -217,13 +217,13 @@ class OverlappingFieldsCanBeMerged $selectionSet2 = $ast2->selectionSet; if ($selectionSet1 && $selectionSet2) { $visitedFragmentNames = new \ArrayObject(); - $subfieldMap = $this->collectFieldASTsAndDefs( + $subfieldMap = $this->collectFieldNodesAndDefs( $context, Type::getNamedType($type1), $selectionSet1, $visitedFragmentNames ); - $subfieldMap = $this->collectFieldASTsAndDefs( + $subfieldMap = $this->collectFieldNodesAndDefs( $context, Type::getNamedType($type2), $selectionSet2, @@ -309,7 +309,7 @@ class OverlappingFieldsCanBeMerged * @param \ArrayObject $astAndDefs * @return mixed */ - private function collectFieldASTsAndDefs(ValidationContext $context, $parentType, SelectionSetNode $selectionSet, \ArrayObject $visitedFragmentNames = null, \ArrayObject $astAndDefs = null) + private function collectFieldNodesAndDefs(ValidationContext $context, $parentType, SelectionSetNode $selectionSet, \ArrayObject $visitedFragmentNames = null, \ArrayObject $astAndDefs = null) { $_visitedFragmentNames = $visitedFragmentNames ?: new \ArrayObject(); $_astAndDefs = $astAndDefs ?: new \ArrayObject(); @@ -340,7 +340,7 @@ class OverlappingFieldsCanBeMerged ? TypeInfo::typeFromAST($context->getSchema(), $typeCondition) : $parentType; - $_astAndDefs = $this->collectFieldASTsAndDefs( + $_astAndDefs = $this->collectFieldNodesAndDefs( $context, $inlineFragmentType, $selection->selectionSet, @@ -360,7 +360,7 @@ class OverlappingFieldsCanBeMerged continue; } $fragmentType = TypeInfo::typeFromAST($context->getSchema(), $fragment->typeCondition); - $_astAndDefs = $this->collectFieldASTsAndDefs( + $_astAndDefs = $this->collectFieldNodesAndDefs( $context, $fragmentType, $fragment->selectionSet, diff --git a/src/Validator/Rules/ProvidedNonNullArguments.php b/src/Validator/Rules/ProvidedNonNullArguments.php index 18ac869..7271395 100644 --- a/src/Validator/Rules/ProvidedNonNullArguments.php +++ b/src/Validator/Rules/ProvidedNonNullArguments.php @@ -28,47 +28,47 @@ class ProvidedNonNullArguments { return [ NodeType::FIELD => [ - 'leave' => function(FieldNode $fieldAST) use ($context) { + 'leave' => function(FieldNode $fieldNode) use ($context) { $fieldDef = $context->getFieldDef(); if (!$fieldDef) { return Visitor::skipNode(); } - $argASTs = $fieldAST->arguments ?: []; + $argNodes = $fieldNode->arguments ?: []; - $argASTMap = []; - foreach ($argASTs as $argAST) { - $argASTMap[$argAST->name->value] = $argASTs; + $argNodeMap = []; + foreach ($argNodes as $argNode) { + $argNodeMap[$argNode->name->value] = $argNodes; } foreach ($fieldDef->args as $argDef) { - $argAST = isset($argASTMap[$argDef->name]) ? $argASTMap[$argDef->name] : null; - if (!$argAST && $argDef->getType() instanceof NonNull) { + $argNode = isset($argNodeMap[$argDef->name]) ? $argNodeMap[$argDef->name] : null; + if (!$argNode && $argDef->getType() instanceof NonNull) { $context->reportError(new Error( - self::missingFieldArgMessage($fieldAST->name->value, $argDef->name, $argDef->getType()), - [$fieldAST] + self::missingFieldArgMessage($fieldNode->name->value, $argDef->name, $argDef->getType()), + [$fieldNode] )); } } } ], NodeType::DIRECTIVE => [ - 'leave' => function(DirectiveNode $directiveAST) use ($context) { + 'leave' => function(DirectiveNode $directiveNode) use ($context) { $directiveDef = $context->getDirective(); if (!$directiveDef) { return Visitor::skipNode(); } - $argASTs = $directiveAST->arguments ?: []; - $argASTMap = []; - foreach ($argASTs as $argAST) { - $argASTMap[$argAST->name->value] = $argASTs; + $argNodes = $directiveNode->arguments ?: []; + $argNodeMap = []; + foreach ($argNodes as $argNode) { + $argNodeMap[$argNode->name->value] = $argNodes; } foreach ($directiveDef->args as $argDef) { - $argAST = isset($argASTMap[$argDef->name]) ? $argASTMap[$argDef->name] : null; - if (!$argAST && $argDef->getType() instanceof NonNull) { + $argNode = isset($argNodeMap[$argDef->name]) ? $argNodeMap[$argDef->name] : null; + if (!$argNode && $argDef->getType() instanceof NonNull) { $context->reportError(new Error( - self::missingDirectiveArgMessage($directiveAST->name->value, $argDef->name, $argDef->getType()), - [$directiveAST] + self::missingDirectiveArgMessage($directiveNode->name->value, $argDef->name, $argDef->getType()), + [$directiveNode] )); } } diff --git a/src/Validator/Rules/QueryComplexity.php b/src/Validator/Rules/QueryComplexity.php index b5c915c..d4701c1 100644 --- a/src/Validator/Rules/QueryComplexity.php +++ b/src/Validator/Rules/QueryComplexity.php @@ -23,7 +23,7 @@ class QueryComplexity extends AbstractQuerySecurity private $variableDefs; - private $fieldAstAndDefs; + private $fieldNodeAndDefs; /** * @var ValidationContext @@ -72,19 +72,19 @@ class QueryComplexity extends AbstractQuerySecurity $this->context = $context; $this->variableDefs = new \ArrayObject(); - $this->fieldAstAndDefs = new \ArrayObject(); + $this->fieldNodeAndDefs = new \ArrayObject(); $complexity = 0; return $this->invokeIfNeeded( $context, [ NodeType::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) { - $this->fieldAstAndDefs = $this->collectFieldASTsAndDefs( + $this->fieldNodeAndDefs = $this->collectFieldASTsAndDefs( $context, $context->getParentType(), $selectionSet, null, - $this->fieldAstAndDefs + $this->fieldNodeAndDefs ); }, NodeType::VARIABLE_DEFINITION => function ($def) { @@ -173,8 +173,8 @@ class QueryComplexity extends AbstractQuerySecurity { $fieldName = $this->getFieldName($field); $astFieldInfo = [null, null]; - if (isset($this->fieldAstAndDefs[$fieldName])) { - foreach ($this->fieldAstAndDefs[$fieldName] as $astAndDef) { + if (isset($this->fieldNodeAndDefs[$fieldName])) { + foreach ($this->fieldNodeAndDefs[$fieldName] as $astAndDef) { if ($astAndDef[0] == $field) { $astFieldInfo = $astAndDef; break; diff --git a/src/Validator/Rules/VariablesInAllowedPosition.php b/src/Validator/Rules/VariablesInAllowedPosition.php index 9cbf673..2f6c06b 100644 --- a/src/Validator/Rules/VariablesInAllowedPosition.php +++ b/src/Validator/Rules/VariablesInAllowedPosition.php @@ -61,8 +61,8 @@ class VariablesInAllowedPosition } } ], - NodeType::VARIABLE_DEFINITION => function (VariableDefinitionNode $varDefAST) { - $this->varDefMap[$varDefAST->variable->name->value] = $varDefAST; + NodeType::VARIABLE_DEFINITION => function (VariableDefinitionNode $varDefNode) { + $this->varDefMap[$varDefNode->variable->name->value] = $varDefNode; } ]; } diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index 9acfbea..5104a42 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -28,10 +28,10 @@ class ErrorTest extends \PHPUnit_Framework_TestCase field }'); $ast = Parser::parse($source); - $fieldAST = $ast->definitions[0]->selectionSet->selections[0]; - $e = new Error('msg', [ $fieldAST ]); + $fieldNode = $ast->definitions[0]->selectionSet->selections[0]; + $e = new Error('msg', [ $fieldNode ]); - $this->assertEquals([$fieldAST], $e->nodes); + $this->assertEquals([$fieldNode], $e->nodes); $this->assertEquals($source, $e->getSource()); $this->assertEquals([8], $e->getPositions()); $this->assertEquals([new SourceLocation(2, 7)], $e->getLocations()); @@ -46,10 +46,10 @@ class ErrorTest extends \PHPUnit_Framework_TestCase field }'); $ast = Parser::parse($source); - $operationAST = $ast->definitions[0]; - $e = new Error('msg', [ $operationAST ]); + $operationNode = $ast->definitions[0]; + $e = new Error('msg', [ $operationNode ]); - $this->assertEquals([$operationAST], $e->nodes); + $this->assertEquals([$operationNode], $e->nodes); $this->assertEquals($source, $e->getSource()); $this->assertEquals([0], $e->getPositions()); $this->assertEquals([new SourceLocation(1, 1)], $e->getLocations()); diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index 12904b5..739477b 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -241,7 +241,7 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase $this->assertEquals([ 'fieldName', - 'fieldASTs', + 'fieldNodes', 'returnType', 'parentType', 'path', @@ -253,8 +253,8 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase ], array_keys((array) $info)); $this->assertEquals('test', $info->fieldName); - $this->assertEquals(1, count($info->fieldASTs)); - $this->assertSame($ast->definitions[0]->selectionSet->selections[0], $info->fieldASTs[0]); + $this->assertEquals(1, count($info->fieldNodes)); + $this->assertSame($ast->definitions[0]->selectionSet->selections[0], $info->fieldNodes[0]); $this->assertSame(Type::string(), $info->returnType); $this->assertSame($schema->getQueryType(), $info->parentType); $this->assertEquals(['result'], $info->path); diff --git a/tests/Executor/TestClasses.php b/tests/Executor/TestClasses.php index a2aac7f..6e53b50 100644 --- a/tests/Executor/TestClasses.php +++ b/tests/Executor/TestClasses.php @@ -68,9 +68,9 @@ class ComplexScalar extends ScalarType return null; } - public function parseLiteral($valueAST) + public function parseLiteral($valueNode) { - if ($valueAST->value === 'SerializedValue') { + if ($valueNode->value === 'SerializedValue') { return 'DeserializedValue'; } return null; diff --git a/tests/Executor/VariablesTest.php b/tests/Executor/VariablesTest.php index 1a2b9c5..25588a0 100644 --- a/tests/Executor/VariablesTest.php +++ b/tests/Executor/VariablesTest.php @@ -124,13 +124,13 @@ class VariablesTest extends \PHPUnit_Framework_TestCase ); // uses default value when not provided: - $withDefaultsAST = Parser::parse(' + $withDefaultsNode = Parser::parse(' query q($input: TestInputObject = {a: "foo", b: ["bar"], c: "baz"}) { fieldWithObjectInput(input: $input) } '); - $result = Executor::execute($this->schema(), $withDefaultsAST)->toArray(); + $result = Executor::execute($this->schema(), $withDefaultsNode)->toArray(); $expected = [ 'data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}'] ];