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