mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-26 06:46:02 +03:00
move to NodeType enum
This commit is contained in:
parent
816fa067b3
commit
d8ca5f4183
@ -7,6 +7,7 @@ use GraphQL\Language\AST\Document;
|
|||||||
use GraphQL\Language\AST\Field;
|
use GraphQL\Language\AST\Field;
|
||||||
use GraphQL\Language\AST\FragmentDefinition;
|
use GraphQL\Language\AST\FragmentDefinition;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Language\AST\SelectionSet;
|
use GraphQL\Language\AST\SelectionSet;
|
||||||
use GraphQL\Schema;
|
use GraphQL\Schema;
|
||||||
@ -119,7 +120,7 @@ class Executor
|
|||||||
|
|
||||||
foreach ($documentAst->definitions as $definition) {
|
foreach ($documentAst->definitions as $definition) {
|
||||||
switch ($definition->kind) {
|
switch ($definition->kind) {
|
||||||
case Node::OPERATION_DEFINITION:
|
case NodeType::OPERATION_DEFINITION:
|
||||||
if (!$operationName && $operation) {
|
if (!$operationName && $operation) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Must provide operation name if query contains multiple operations.'
|
'Must provide operation name if query contains multiple operations.'
|
||||||
@ -130,7 +131,7 @@ class Executor
|
|||||||
$operation = $definition;
|
$operation = $definition;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Node::FRAGMENT_DEFINITION:
|
case NodeType::FRAGMENT_DEFINITION:
|
||||||
$fragments[$definition->name->value] = $definition;
|
$fragments[$definition->name->value] = $definition;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -271,7 +272,7 @@ class Executor
|
|||||||
{
|
{
|
||||||
foreach ($selectionSet->selections as $selection) {
|
foreach ($selectionSet->selections as $selection) {
|
||||||
switch ($selection->kind) {
|
switch ($selection->kind) {
|
||||||
case Node::FIELD:
|
case NodeType::FIELD:
|
||||||
if (!self::shouldIncludeNode($exeContext, $selection->directives)) {
|
if (!self::shouldIncludeNode($exeContext, $selection->directives)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -281,7 +282,7 @@ class Executor
|
|||||||
}
|
}
|
||||||
$fields[$name][] = $selection;
|
$fields[$name][] = $selection;
|
||||||
break;
|
break;
|
||||||
case Node::INLINE_FRAGMENT:
|
case NodeType::INLINE_FRAGMENT:
|
||||||
if (!self::shouldIncludeNode($exeContext, $selection->directives) ||
|
if (!self::shouldIncludeNode($exeContext, $selection->directives) ||
|
||||||
!self::doesFragmentConditionMatch($exeContext, $selection, $runtimeType)
|
!self::doesFragmentConditionMatch($exeContext, $selection, $runtimeType)
|
||||||
) {
|
) {
|
||||||
@ -295,7 +296,7 @@ class Executor
|
|||||||
$visitedFragmentNames
|
$visitedFragmentNames
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case Node::FRAGMENT_SPREAD:
|
case NodeType::FRAGMENT_SPREAD:
|
||||||
$fragName = $selection->name->value;
|
$fragName = $selection->name->value;
|
||||||
if (!empty($visitedFragmentNames[$fragName]) || !self::shouldIncludeNode($exeContext, $selection->directives)) {
|
if (!empty($visitedFragmentNames[$fragName]) || !self::shouldIncludeNode($exeContext, $selection->directives)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -7,6 +7,7 @@ use GraphQL\Language\AST\ListValue;
|
|||||||
use GraphQL\Language\AST\Document;
|
use GraphQL\Language\AST\Document;
|
||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\Value;
|
use GraphQL\Language\AST\Value;
|
||||||
use GraphQL\Language\AST\Variable;
|
use GraphQL\Language\AST\Variable;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
@ -195,7 +196,7 @@ class DocumentValidator
|
|||||||
|
|
||||||
// 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 !== Node::OBJECT) {
|
if ($valueAST->kind !== NodeType::OBJECT) {
|
||||||
return [ "Expected \"{$type->name}\", found not an object." ];
|
return [ "Expected \"{$type->name}\", found not an object." ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ use GraphQL\Language\AST\FragmentDefinition;
|
|||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\InlineFragment;
|
use GraphQL\Language\AST\InlineFragment;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\SelectionSet;
|
use GraphQL\Language\AST\SelectionSet;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use GraphQL\Type\Introspection;
|
use GraphQL\Type\Introspection;
|
||||||
@ -99,7 +100,7 @@ abstract class AbstractQuerySecurity
|
|||||||
|
|
||||||
foreach ($selectionSet->selections as $selection) {
|
foreach ($selectionSet->selections as $selection) {
|
||||||
switch ($selection->kind) {
|
switch ($selection->kind) {
|
||||||
case Node::FIELD:
|
case NodeType::FIELD:
|
||||||
/* @var Field $selection */
|
/* @var Field $selection */
|
||||||
$fieldName = $selection->name->value;
|
$fieldName = $selection->name->value;
|
||||||
$fieldDef = null;
|
$fieldDef = null;
|
||||||
@ -126,7 +127,7 @@ abstract class AbstractQuerySecurity
|
|||||||
// create field context
|
// create field context
|
||||||
$_astAndDefs[$responseName][] = [$selection, $fieldDef];
|
$_astAndDefs[$responseName][] = [$selection, $fieldDef];
|
||||||
break;
|
break;
|
||||||
case Node::INLINE_FRAGMENT:
|
case NodeType::INLINE_FRAGMENT:
|
||||||
/* @var InlineFragment $selection */
|
/* @var InlineFragment $selection */
|
||||||
$_astAndDefs = $this->collectFieldASTsAndDefs(
|
$_astAndDefs = $this->collectFieldASTsAndDefs(
|
||||||
$context,
|
$context,
|
||||||
@ -136,7 +137,7 @@ abstract class AbstractQuerySecurity
|
|||||||
$_astAndDefs
|
$_astAndDefs
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case Node::FRAGMENT_SPREAD:
|
case NodeType::FRAGMENT_SPREAD:
|
||||||
/* @var FragmentSpread $selection */
|
/* @var FragmentSpread $selection */
|
||||||
$fragName = $selection->name->value;
|
$fragName = $selection->name->value;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\Argument;
|
use GraphQL\Language\AST\Argument;
|
||||||
use GraphQL\Language\AST\Field;
|
use GraphQL\Language\AST\Field;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Type\Definition\NonNull;
|
use GraphQL\Type\Definition\NonNull;
|
||||||
@ -25,7 +26,7 @@ class ArgumentsOfCorrectType
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::ARGUMENT => function(Argument $argAST) use ($context) {
|
NodeType::ARGUMENT => function(Argument $argAST) use ($context) {
|
||||||
$argDef = $context->getArgument();
|
$argDef = $context->getArgument();
|
||||||
if ($argDef) {
|
if ($argDef) {
|
||||||
$errors = DocumentValidator::isValidLiteralValue($argDef->getType(), $argAST->value);
|
$errors = DocumentValidator::isValidLiteralValue($argDef->getType(), $argAST->value);
|
||||||
|
@ -4,6 +4,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\VariableDefinition;
|
use GraphQL\Language\AST\VariableDefinition;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
@ -29,7 +30,7 @@ class DefaultValuesOfCorrectType
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::VARIABLE_DEFINITION => function(VariableDefinition $varDefAST) use ($context) {
|
NodeType::VARIABLE_DEFINITION => function(VariableDefinition $varDefAST) use ($context) {
|
||||||
$name = $varDefAST->variable->name->value;
|
$name = $varDefAST->variable->name->value;
|
||||||
$defaultValue = $varDefAST->defaultValue;
|
$defaultValue = $varDefAST->defaultValue;
|
||||||
$type = $context->getInputType();
|
$type = $context->getInputType();
|
||||||
@ -51,8 +52,8 @@ class DefaultValuesOfCorrectType
|
|||||||
}
|
}
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
},
|
},
|
||||||
Node::SELECTION_SET => function() {return Visitor::skipNode();},
|
NodeType::SELECTION_SET => function() {return Visitor::skipNode();},
|
||||||
Node::FRAGMENT_DEFINITION => function() {return Visitor::skipNode();}
|
NodeType::FRAGMENT_DEFINITION => function() {return Visitor::skipNode();}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Field;
|
use GraphQL\Language\AST\Field;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Schema;
|
use GraphQL\Schema;
|
||||||
use GraphQL\Type\Definition\AbstractType;
|
use GraphQL\Type\Definition\AbstractType;
|
||||||
use GraphQL\Utils;
|
use GraphQL\Utils;
|
||||||
@ -36,7 +37,7 @@ class FieldsOnCorrectType
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::FIELD => function(Field $node) use ($context) {
|
NodeType::FIELD => function(Field $node) use ($context) {
|
||||||
$type = $context->getParentType();
|
$type = $context->getParentType();
|
||||||
if ($type) {
|
if ($type) {
|
||||||
$fieldDef = $context->getFieldDef();
|
$fieldDef = $context->getFieldDef();
|
||||||
|
@ -6,6 +6,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\FragmentDefinition;
|
use GraphQL\Language\AST\FragmentDefinition;
|
||||||
use GraphQL\Language\AST\InlineFragment;
|
use GraphQL\Language\AST\InlineFragment;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
use GraphQL\Type\Definition\CompositeType;
|
use GraphQL\Type\Definition\CompositeType;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
@ -27,7 +28,7 @@ class FragmentsOnCompositeTypes
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::INLINE_FRAGMENT => function(InlineFragment $node) use ($context) {
|
NodeType::INLINE_FRAGMENT => function(InlineFragment $node) use ($context) {
|
||||||
$type = $context->getType();
|
$type = $context->getType();
|
||||||
|
|
||||||
if ($node->typeCondition && $type && !Type::isCompositeType($type)) {
|
if ($node->typeCondition && $type && !Type::isCompositeType($type)) {
|
||||||
@ -37,7 +38,7 @@ class FragmentsOnCompositeTypes
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Node::FRAGMENT_DEFINITION => function(FragmentDefinition $node) use ($context) {
|
NodeType::FRAGMENT_DEFINITION => function(FragmentDefinition $node) use ($context) {
|
||||||
$type = $context->getType();
|
$type = $context->getType();
|
||||||
|
|
||||||
if ($type && !Type::isCompositeType($type)) {
|
if ($type && !Type::isCompositeType($type)) {
|
||||||
|
@ -5,6 +5,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Argument;
|
use GraphQL\Language\AST\Argument;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Utils;
|
use GraphQL\Utils;
|
||||||
use GraphQL\Validator\Messages;
|
use GraphQL\Validator\Messages;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -24,9 +25,9 @@ class KnownArgumentNames
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::ARGUMENT => function(Argument $node, $key, $parent, $path, $ancestors) use ($context) {
|
NodeType::ARGUMENT => function(Argument $node, $key, $parent, $path, $ancestors) use ($context) {
|
||||||
$argumentOf = $ancestors[count($ancestors) - 1];
|
$argumentOf = $ancestors[count($ancestors) - 1];
|
||||||
if ($argumentOf->kind === Node::FIELD) {
|
if ($argumentOf->kind === NodeType::FIELD) {
|
||||||
$fieldDef = $context->getFieldDef();
|
$fieldDef = $context->getFieldDef();
|
||||||
|
|
||||||
if ($fieldDef) {
|
if ($fieldDef) {
|
||||||
@ -46,7 +47,7 @@ class KnownArgumentNames
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($argumentOf->kind === Node::DIRECTIVE) {
|
} else if ($argumentOf->kind === NodeType::DIRECTIVE) {
|
||||||
$directive = $context->getDirective();
|
$directive = $context->getDirective();
|
||||||
if ($directive) {
|
if ($directive) {
|
||||||
$directiveArgDef = null;
|
$directiveArgDef = null;
|
||||||
|
@ -9,6 +9,7 @@ use GraphQL\Language\AST\FragmentDefinition;
|
|||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\InlineFragment;
|
use GraphQL\Language\AST\InlineFragment;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Validator\Messages;
|
use GraphQL\Validator\Messages;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -29,7 +30,7 @@ class KnownDirectives
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::DIRECTIVE => function (Directive $node, $key, $parent, $path, $ancestors) use ($context) {
|
NodeType::DIRECTIVE => function (Directive $node, $key, $parent, $path, $ancestors) use ($context) {
|
||||||
$directiveDef = null;
|
$directiveDef = null;
|
||||||
foreach ($context->getSchema()->getDirectives() as $def) {
|
foreach ($context->getSchema()->getDirectives() as $def) {
|
||||||
if ($def->name === $node->name->value) {
|
if ($def->name === $node->name->value) {
|
||||||
@ -66,17 +67,17 @@ class KnownDirectives
|
|||||||
private function getLocationForAppliedNode(Node $appliedTo)
|
private function getLocationForAppliedNode(Node $appliedTo)
|
||||||
{
|
{
|
||||||
switch ($appliedTo->kind) {
|
switch ($appliedTo->kind) {
|
||||||
case Node::OPERATION_DEFINITION:
|
case NodeType::OPERATION_DEFINITION:
|
||||||
switch ($appliedTo->operation) {
|
switch ($appliedTo->operation) {
|
||||||
case 'query': return DirectiveDef::LOCATION_QUERY;
|
case 'query': return DirectiveDef::LOCATION_QUERY;
|
||||||
case 'mutation': return DirectiveDef::LOCATION_MUTATION;
|
case 'mutation': return DirectiveDef::LOCATION_MUTATION;
|
||||||
case 'subscription': return DirectiveDef::LOCATION_SUBSCRIPTION;
|
case 'subscription': return DirectiveDef::LOCATION_SUBSCRIPTION;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Node::FIELD: return DirectiveDef::LOCATION_FIELD;
|
case NodeType::FIELD: return DirectiveDef::LOCATION_FIELD;
|
||||||
case Node::FRAGMENT_SPREAD: return DirectiveDef::LOCATION_FRAGMENT_SPREAD;
|
case NodeType::FRAGMENT_SPREAD: return DirectiveDef::LOCATION_FRAGMENT_SPREAD;
|
||||||
case Node::INLINE_FRAGMENT: return DirectiveDef::LOCATION_INLINE_FRAGMENT;
|
case NodeType::INLINE_FRAGMENT: return DirectiveDef::LOCATION_INLINE_FRAGMENT;
|
||||||
case Node::FRAGMENT_DEFINITION: return DirectiveDef::LOCATION_FRAGMENT_DEFINITION;
|
case NodeType::FRAGMENT_DEFINITION: return DirectiveDef::LOCATION_FRAGMENT_DEFINITION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
|
|
||||||
class KnownFragmentNames
|
class KnownFragmentNames
|
||||||
@ -17,7 +18,7 @@ class KnownFragmentNames
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::FRAGMENT_SPREAD => function(FragmentSpread $node) use ($context) {
|
NodeType::FRAGMENT_SPREAD => function(FragmentSpread $node) use ($context) {
|
||||||
$fragmentName = $node->name->value;
|
$fragmentName = $node->name->value;
|
||||||
$fragment = $context->getFragment($fragmentName);
|
$fragment = $context->getFragment($fragmentName);
|
||||||
if (!$fragment) {
|
if (!$fragment) {
|
||||||
|
@ -22,12 +22,12 @@ class KnownTypeNames
|
|||||||
$skip = function() {return Visitor::skipNode();};
|
$skip = function() {return Visitor::skipNode();};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OBJECT_TYPE_DEFINITION => $skip,
|
NodeType::OBJECT_TYPE_DEFINITION => $skip,
|
||||||
Node::INTERFACE_TYPE_DEFINITION => $skip,
|
NodeType::INTERFACE_TYPE_DEFINITION => $skip,
|
||||||
Node::UNION_TYPE_DEFINITION => $skip,
|
NodeType::UNION_TYPE_DEFINITION => $skip,
|
||||||
Node::INPUT_OBJECT_TYPE_DEFINITION => $skip,
|
NodeType::INPUT_OBJECT_TYPE_DEFINITION => $skip,
|
||||||
|
|
||||||
Node::NAMED_TYPE => function(NamedType $node, $key) use ($context) {
|
NodeType::NAMED_TYPE => function(NamedType $node, $key) use ($context) {
|
||||||
$typeName = $node->name->value;
|
$typeName = $node->name->value;
|
||||||
$type = $context->getSchema()->getType($typeName);
|
$type = $context->getSchema()->getType($typeName);
|
||||||
if (!$type) {
|
if (!$type) {
|
||||||
|
@ -4,6 +4,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Document;
|
use GraphQL\Language\AST\Document;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Utils;
|
use GraphQL\Utils;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -25,16 +26,16 @@ class LoneAnonymousOperation
|
|||||||
{
|
{
|
||||||
$operationCount = 0;
|
$operationCount = 0;
|
||||||
return [
|
return [
|
||||||
Node::DOCUMENT => function(Document $node) use (&$operationCount) {
|
NodeType::DOCUMENT => function(Document $node) use (&$operationCount) {
|
||||||
$tmp = Utils::filter(
|
$tmp = Utils::filter(
|
||||||
$node->definitions,
|
$node->definitions,
|
||||||
function ($definition) {
|
function ($definition) {
|
||||||
return $definition->kind === Node::OPERATION_DEFINITION;
|
return $definition->kind === NodeType::OPERATION_DEFINITION;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$operationCount = count($tmp);
|
$operationCount = count($tmp);
|
||||||
},
|
},
|
||||||
Node::OPERATION_DEFINITION => function(OperationDefinition $node) use (&$operationCount, $context) {
|
NodeType::OPERATION_DEFINITION => function(OperationDefinition $node) use (&$operationCount, $context) {
|
||||||
if (!$node->name && $operationCount > 1) {
|
if (!$node->name && $operationCount > 1) {
|
||||||
$context->reportError(
|
$context->reportError(
|
||||||
new Error(self::anonOperationNotAloneMessage(), [$node])
|
new Error(self::anonOperationNotAloneMessage(), [$node])
|
||||||
|
@ -13,6 +13,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\FragmentDefinition;
|
use GraphQL\Language\AST\FragmentDefinition;
|
||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Utils;
|
use GraphQL\Utils;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -44,10 +45,10 @@ class NoFragmentCycles
|
|||||||
$this->spreadPathIndexByName = [];
|
$this->spreadPathIndexByName = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => function () {
|
NodeType::OPERATION_DEFINITION => function () {
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
},
|
},
|
||||||
Node::FRAGMENT_DEFINITION => function (FragmentDefinition $node) use ($context) {
|
NodeType::FRAGMENT_DEFINITION => function (FragmentDefinition $node) use ($context) {
|
||||||
if (!isset($this->visitedFrags[$node->name->value])) {
|
if (!isset($this->visitedFrags[$node->name->value])) {
|
||||||
$this->detectCycleRecursive($node, $context);
|
$this->detectCycleRecursive($node, $context);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\FragmentDefinition;
|
use GraphQL\Language\AST\FragmentDefinition;
|
||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Language\AST\Variable;
|
use GraphQL\Language\AST\Variable;
|
||||||
use GraphQL\Language\AST\VariableDefinition;
|
use GraphQL\Language\AST\VariableDefinition;
|
||||||
@ -35,7 +36,7 @@ class NoUndefinedVariables
|
|||||||
$variableNameDefined = [];
|
$variableNameDefined = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => [
|
NodeType::OPERATION_DEFINITION => [
|
||||||
'enter' => function() use (&$variableNameDefined) {
|
'enter' => function() use (&$variableNameDefined) {
|
||||||
$variableNameDefined = [];
|
$variableNameDefined = [];
|
||||||
},
|
},
|
||||||
@ -58,7 +59,7 @@ class NoUndefinedVariables
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
Node::VARIABLE_DEFINITION => function(VariableDefinition $def) use (&$variableNameDefined) {
|
NodeType::VARIABLE_DEFINITION => function(VariableDefinition $def) use (&$variableNameDefined) {
|
||||||
$variableNameDefined[$def->variable->name->value] = true;
|
$variableNameDefined[$def->variable->name->value] = true;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -6,6 +6,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\FragmentDefinition;
|
use GraphQL\Language\AST\FragmentDefinition;
|
||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Validator\Messages;
|
use GraphQL\Validator\Messages;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -27,15 +28,15 @@ class NoUnusedFragments
|
|||||||
$this->fragmentDefs = [];
|
$this->fragmentDefs = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => function($node) {
|
NodeType::OPERATION_DEFINITION => function($node) {
|
||||||
$this->operationDefs[] = $node;
|
$this->operationDefs[] = $node;
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
},
|
},
|
||||||
Node::FRAGMENT_DEFINITION => function(FragmentDefinition $def) {
|
NodeType::FRAGMENT_DEFINITION => function(FragmentDefinition $def) {
|
||||||
$this->fragmentDefs[] = $def;
|
$this->fragmentDefs[] = $def;
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
},
|
},
|
||||||
Node::DOCUMENT => [
|
NodeType::DOCUMENT => [
|
||||||
'leave' => function() use ($context) {
|
'leave' => function() use ($context) {
|
||||||
$fragmentNameUsed = [];
|
$fragmentNameUsed = [];
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Validator\Messages;
|
use GraphQL\Validator\Messages;
|
||||||
@ -25,7 +26,7 @@ class NoUnusedVariables
|
|||||||
$this->variableDefs = [];
|
$this->variableDefs = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => [
|
NodeType::OPERATION_DEFINITION => [
|
||||||
'enter' => function() {
|
'enter' => function() {
|
||||||
$this->variableDefs = [];
|
$this->variableDefs = [];
|
||||||
},
|
},
|
||||||
@ -51,7 +52,7 @@ class NoUnusedVariables
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
Node::VARIABLE_DEFINITION => function($def) {
|
NodeType::VARIABLE_DEFINITION => function($def) {
|
||||||
$this->variableDefs[] = $def;
|
$this->variableDefs[] = $def;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -9,6 +9,7 @@ use GraphQL\Language\AST\FragmentSpread;
|
|||||||
use GraphQL\Language\AST\InlineFragment;
|
use GraphQL\Language\AST\InlineFragment;
|
||||||
use GraphQL\Language\AST\NamedType;
|
use GraphQL\Language\AST\NamedType;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\SelectionSet;
|
use GraphQL\Language\AST\SelectionSet;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
use GraphQL\Type\Definition\ListOfType;
|
use GraphQL\Type\Definition\ListOfType;
|
||||||
@ -52,7 +53,7 @@ class OverlappingFieldsCanBeMerged
|
|||||||
$this->comparedSet = new PairSet();
|
$this->comparedSet = new PairSet();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::SELECTION_SET => [
|
NodeType::SELECTION_SET => [
|
||||||
// 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(SelectionSet $selectionSet) use ($context) {
|
'leave' => function(SelectionSet $selectionSet) use ($context) {
|
||||||
@ -316,7 +317,7 @@ class OverlappingFieldsCanBeMerged
|
|||||||
$selection = $selectionSet->selections[$i];
|
$selection = $selectionSet->selections[$i];
|
||||||
|
|
||||||
switch ($selection->kind) {
|
switch ($selection->kind) {
|
||||||
case Node::FIELD:
|
case NodeType::FIELD:
|
||||||
$fieldName = $selection->name->value;
|
$fieldName = $selection->name->value;
|
||||||
$fieldDef = null;
|
$fieldDef = null;
|
||||||
if ($parentType && method_exists($parentType, 'getFields')) {
|
if ($parentType && method_exists($parentType, 'getFields')) {
|
||||||
@ -332,7 +333,7 @@ class OverlappingFieldsCanBeMerged
|
|||||||
}
|
}
|
||||||
$_astAndDefs[$responseName][] = [$parentType, $selection, $fieldDef];
|
$_astAndDefs[$responseName][] = [$parentType, $selection, $fieldDef];
|
||||||
break;
|
break;
|
||||||
case Node::INLINE_FRAGMENT:
|
case NodeType::INLINE_FRAGMENT:
|
||||||
$typeCondition = $selection->typeCondition;
|
$typeCondition = $selection->typeCondition;
|
||||||
$inlineFragmentType = $typeCondition
|
$inlineFragmentType = $typeCondition
|
||||||
? TypeInfo::typeFromAST($context->getSchema(), $typeCondition)
|
? TypeInfo::typeFromAST($context->getSchema(), $typeCondition)
|
||||||
@ -346,7 +347,7 @@ class OverlappingFieldsCanBeMerged
|
|||||||
$_astAndDefs
|
$_astAndDefs
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case Node::FRAGMENT_SPREAD:
|
case NodeType::FRAGMENT_SPREAD:
|
||||||
/** @var FragmentSpread $selection */
|
/** @var FragmentSpread $selection */
|
||||||
$fragName = $selection->name->value;
|
$fragName = $selection->name->value;
|
||||||
if (!empty($_visitedFragmentNames[$fragName])) {
|
if (!empty($_visitedFragmentNames[$fragName])) {
|
||||||
|
@ -6,6 +6,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\InlineFragment;
|
use GraphQL\Language\AST\InlineFragment;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Utils;
|
use GraphQL\Utils;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
use GraphQL\Utils\TypeInfo;
|
use GraphQL\Utils\TypeInfo;
|
||||||
@ -25,7 +26,7 @@ class PossibleFragmentSpreads
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::INLINE_FRAGMENT => function(InlineFragment $node) use ($context) {
|
NodeType::INLINE_FRAGMENT => function(InlineFragment $node) use ($context) {
|
||||||
$fragType = $context->getType();
|
$fragType = $context->getType();
|
||||||
$parentType = $context->getParentType();
|
$parentType = $context->getParentType();
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ class PossibleFragmentSpreads
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Node::FRAGMENT_SPREAD => function(FragmentSpread $node) use ($context) {
|
NodeType::FRAGMENT_SPREAD => function(FragmentSpread $node) use ($context) {
|
||||||
$fragName = $node->name->value;
|
$fragName = $node->name->value;
|
||||||
$fragType = $this->getFragmentType($context, $fragName);
|
$fragType = $this->getFragmentType($context, $fragName);
|
||||||
$parentType = $context->getParentType();
|
$parentType = $context->getParentType();
|
||||||
|
@ -6,6 +6,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\Directive;
|
use GraphQL\Language\AST\Directive;
|
||||||
use GraphQL\Language\AST\Field;
|
use GraphQL\Language\AST\Field;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Type\Definition\NonNull;
|
use GraphQL\Type\Definition\NonNull;
|
||||||
use GraphQL\Utils;
|
use GraphQL\Utils;
|
||||||
@ -26,7 +27,7 @@ class ProvidedNonNullArguments
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::FIELD => [
|
NodeType::FIELD => [
|
||||||
'leave' => function(Field $fieldAST) use ($context) {
|
'leave' => function(Field $fieldAST) use ($context) {
|
||||||
$fieldDef = $context->getFieldDef();
|
$fieldDef = $context->getFieldDef();
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ class ProvidedNonNullArguments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
Node::DIRECTIVE => [
|
NodeType::DIRECTIVE => [
|
||||||
'leave' => function(Directive $directiveAST) use ($context) {
|
'leave' => function(Directive $directiveAST) use ($context) {
|
||||||
$directiveDef = $context->getDirective();
|
$directiveDef = $context->getDirective();
|
||||||
if (!$directiveDef) {
|
if (!$directiveDef) {
|
||||||
|
@ -8,6 +8,7 @@ use GraphQL\Language\AST\Field;
|
|||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\InlineFragment;
|
use GraphQL\Language\AST\InlineFragment;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Language\AST\SelectionSet;
|
use GraphQL\Language\AST\SelectionSet;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
@ -77,7 +78,7 @@ class QueryComplexity extends AbstractQuerySecurity
|
|||||||
return $this->invokeIfNeeded(
|
return $this->invokeIfNeeded(
|
||||||
$context,
|
$context,
|
||||||
[
|
[
|
||||||
Node::SELECTION_SET => function (SelectionSet $selectionSet) use ($context) {
|
NodeType::SELECTION_SET => function (SelectionSet $selectionSet) use ($context) {
|
||||||
$this->fieldAstAndDefs = $this->collectFieldASTsAndDefs(
|
$this->fieldAstAndDefs = $this->collectFieldASTsAndDefs(
|
||||||
$context,
|
$context,
|
||||||
$context->getParentType(),
|
$context->getParentType(),
|
||||||
@ -86,11 +87,11 @@ class QueryComplexity extends AbstractQuerySecurity
|
|||||||
$this->fieldAstAndDefs
|
$this->fieldAstAndDefs
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Node::VARIABLE_DEFINITION => function ($def) {
|
NodeType::VARIABLE_DEFINITION => function ($def) {
|
||||||
$this->variableDefs[] = $def;
|
$this->variableDefs[] = $def;
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
},
|
},
|
||||||
Node::OPERATION_DEFINITION => [
|
NodeType::OPERATION_DEFINITION => [
|
||||||
'leave' => function (OperationDefinition $operationDefinition) use ($context, &$complexity) {
|
'leave' => function (OperationDefinition $operationDefinition) use ($context, &$complexity) {
|
||||||
$complexity = $this->fieldComplexity($operationDefinition, $complexity);
|
$complexity = $this->fieldComplexity($operationDefinition, $complexity);
|
||||||
|
|
||||||
@ -119,7 +120,7 @@ class QueryComplexity extends AbstractQuerySecurity
|
|||||||
private function nodeComplexity(Node $node, $complexity = 0)
|
private function nodeComplexity(Node $node, $complexity = 0)
|
||||||
{
|
{
|
||||||
switch ($node->kind) {
|
switch ($node->kind) {
|
||||||
case Node::FIELD:
|
case NodeType::FIELD:
|
||||||
/* @var Field $node */
|
/* @var Field $node */
|
||||||
// default values
|
// default values
|
||||||
$args = [];
|
$args = [];
|
||||||
@ -147,7 +148,7 @@ class QueryComplexity extends AbstractQuerySecurity
|
|||||||
$complexity += call_user_func_array($complexityFn, [$childrenComplexity, $args]);
|
$complexity += call_user_func_array($complexityFn, [$childrenComplexity, $args]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Node::INLINE_FRAGMENT:
|
case NodeType::INLINE_FRAGMENT:
|
||||||
/* @var InlineFragment $node */
|
/* @var InlineFragment $node */
|
||||||
// node has children?
|
// node has children?
|
||||||
if (isset($node->selectionSet)) {
|
if (isset($node->selectionSet)) {
|
||||||
@ -155,7 +156,7 @@ class QueryComplexity extends AbstractQuerySecurity
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Node::FRAGMENT_SPREAD:
|
case NodeType::FRAGMENT_SPREAD:
|
||||||
/* @var FragmentSpread $node */
|
/* @var FragmentSpread $node */
|
||||||
$fragment = $this->getFragment($node);
|
$fragment = $this->getFragment($node);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class QueryDepth extends AbstractQuerySecurity
|
|||||||
return $this->invokeIfNeeded(
|
return $this->invokeIfNeeded(
|
||||||
$context,
|
$context,
|
||||||
[
|
[
|
||||||
Node::OPERATION_DEFINITION => [
|
NodeType::OPERATION_DEFINITION => [
|
||||||
'leave' => function (OperationDefinition $operationDefinition) use ($context) {
|
'leave' => function (OperationDefinition $operationDefinition) use ($context) {
|
||||||
$maxDepth = $this->fieldDepth($operationDefinition);
|
$maxDepth = $this->fieldDepth($operationDefinition);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ class QueryDepth extends AbstractQuerySecurity
|
|||||||
private function nodeDepth(Node $node, $depth = 0, $maxDepth = 0)
|
private function nodeDepth(Node $node, $depth = 0, $maxDepth = 0)
|
||||||
{
|
{
|
||||||
switch ($node->kind) {
|
switch ($node->kind) {
|
||||||
case Node::FIELD:
|
case NodeType::FIELD:
|
||||||
/* @var Field $node */
|
/* @var Field $node */
|
||||||
// node has children?
|
// node has children?
|
||||||
if (null !== $node->selectionSet) {
|
if (null !== $node->selectionSet) {
|
||||||
@ -95,7 +95,7 @@ class QueryDepth extends AbstractQuerySecurity
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Node::INLINE_FRAGMENT:
|
case NodeType::INLINE_FRAGMENT:
|
||||||
/* @var InlineFragment $node */
|
/* @var InlineFragment $node */
|
||||||
// node has children?
|
// node has children?
|
||||||
if (null !== $node->selectionSet) {
|
if (null !== $node->selectionSet) {
|
||||||
@ -103,7 +103,7 @@ class QueryDepth extends AbstractQuerySecurity
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Node::FRAGMENT_SPREAD:
|
case NodeType::FRAGMENT_SPREAD:
|
||||||
/* @var FragmentSpread $node */
|
/* @var FragmentSpread $node */
|
||||||
$fragment = $this->getFragment($node);
|
$fragment = $this->getFragment($node);
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Field;
|
use GraphQL\Language\AST\Field;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use GraphQL\Validator\Messages;
|
use GraphQL\Validator\Messages;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -24,7 +25,7 @@ class ScalarLeafs
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::FIELD => function(Field $node) use ($context) {
|
NodeType::FIELD => function(Field $node) use ($context) {
|
||||||
$type = $context->getType();
|
$type = $context->getType();
|
||||||
if ($type) {
|
if ($type) {
|
||||||
if (Type::isLeafType($type)) {
|
if (Type::isLeafType($type)) {
|
||||||
|
@ -4,6 +4,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Argument;
|
use GraphQL\Language\AST\Argument;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
|
|
||||||
@ -21,13 +22,13 @@ class UniqueArgumentNames
|
|||||||
$this->knownArgNames = [];
|
$this->knownArgNames = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::FIELD => function () {
|
NodeType::FIELD => function () {
|
||||||
$this->knownArgNames = [];;
|
$this->knownArgNames = [];;
|
||||||
},
|
},
|
||||||
Node::DIRECTIVE => function () {
|
NodeType::DIRECTIVE => function () {
|
||||||
$this->knownArgNames = [];
|
$this->knownArgNames = [];
|
||||||
},
|
},
|
||||||
Node::ARGUMENT => function (Argument $node) use ($context) {
|
NodeType::ARGUMENT => function (Argument $node) use ($context) {
|
||||||
$argName = $node->name->value;
|
$argName = $node->name->value;
|
||||||
if (!empty($this->knownArgNames[$argName])) {
|
if (!empty($this->knownArgNames[$argName])) {
|
||||||
$context->reportError(new Error(
|
$context->reportError(new Error(
|
||||||
|
@ -5,6 +5,7 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Language\AST\Argument;
|
use GraphQL\Language\AST\Argument;
|
||||||
use GraphQL\Language\AST\FragmentDefinition;
|
use GraphQL\Language\AST\FragmentDefinition;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
|
|
||||||
@ -22,10 +23,10 @@ class UniqueFragmentNames
|
|||||||
$this->knownFragmentNames = [];
|
$this->knownFragmentNames = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => function () {
|
NodeType::OPERATION_DEFINITION => function () {
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
},
|
},
|
||||||
Node::FRAGMENT_DEFINITION => function (FragmentDefinition $node) use ($context) {
|
NodeType::FRAGMENT_DEFINITION => function (FragmentDefinition $node) use ($context) {
|
||||||
$fragmentName = $node->name->value;
|
$fragmentName = $node->name->value;
|
||||||
if (!empty($this->knownFragmentNames[$fragmentName])) {
|
if (!empty($this->knownFragmentNames[$fragmentName])) {
|
||||||
$context->reportError(new Error(
|
$context->reportError(new Error(
|
||||||
|
@ -3,6 +3,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\ObjectField;
|
use GraphQL\Language\AST\ObjectField;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -23,7 +24,7 @@ class UniqueInputFieldNames
|
|||||||
$this->knownNameStack = [];
|
$this->knownNameStack = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OBJECT => [
|
NodeType::OBJECT => [
|
||||||
'enter' => function() {
|
'enter' => function() {
|
||||||
$this->knownNameStack[] = $this->knownNames;
|
$this->knownNameStack[] = $this->knownNames;
|
||||||
$this->knownNames = [];
|
$this->knownNames = [];
|
||||||
@ -32,7 +33,7 @@ class UniqueInputFieldNames
|
|||||||
$this->knownNames = array_pop($this->knownNameStack);
|
$this->knownNames = array_pop($this->knownNameStack);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
Node::OBJECT_FIELD => function(ObjectField $node) use ($context) {
|
NodeType::OBJECT_FIELD => function(ObjectField $node) use ($context) {
|
||||||
$fieldName = $node->name->value;
|
$fieldName = $node->name->value;
|
||||||
|
|
||||||
if (!empty($this->knownNames[$fieldName])) {
|
if (!empty($this->knownNames[$fieldName])) {
|
||||||
|
@ -3,6 +3,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
@ -21,7 +22,7 @@ class UniqueOperationNames
|
|||||||
$this->knownOperationNames = [];
|
$this->knownOperationNames = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => function(OperationDefinition $node) use ($context) {
|
NodeType::OPERATION_DEFINITION => function(OperationDefinition $node) use ($context) {
|
||||||
$operationName = $node->name;
|
$operationName = $node->name;
|
||||||
|
|
||||||
if ($operationName) {
|
if ($operationName) {
|
||||||
@ -36,7 +37,7 @@ class UniqueOperationNames
|
|||||||
}
|
}
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
},
|
},
|
||||||
Node::FRAGMENT_DEFINITION => function() {
|
NodeType::FRAGMENT_DEFINITION => function() {
|
||||||
return Visitor::skipNode();
|
return Visitor::skipNode();
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -3,6 +3,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\VariableDefinition;
|
use GraphQL\Language\AST\VariableDefinition;
|
||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
|
|
||||||
@ -20,10 +21,10 @@ class UniqueVariableNames
|
|||||||
$this->knownVariableNames = [];
|
$this->knownVariableNames = [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => function() {
|
NodeType::OPERATION_DEFINITION => function() {
|
||||||
$this->knownVariableNames = [];
|
$this->knownVariableNames = [];
|
||||||
},
|
},
|
||||||
Node::VARIABLE_DEFINITION => function(VariableDefinition $node) use ($context) {
|
NodeType::VARIABLE_DEFINITION => function(VariableDefinition $node) use ($context) {
|
||||||
$variableName = $node->variable->name->value;
|
$variableName = $node->variable->name->value;
|
||||||
if (!empty($this->knownVariableNames[$variableName])) {
|
if (!empty($this->knownVariableNames[$variableName])) {
|
||||||
$context->reportError(new Error(
|
$context->reportError(new Error(
|
||||||
|
@ -4,6 +4,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\VariableDefinition;
|
use GraphQL\Language\AST\VariableDefinition;
|
||||||
use GraphQL\Language\Printer;
|
use GraphQL\Language\Printer;
|
||||||
use GraphQL\Type\Definition\InputType;
|
use GraphQL\Type\Definition\InputType;
|
||||||
@ -21,7 +22,7 @@ class VariablesAreInputTypes
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::VARIABLE_DEFINITION => function(VariableDefinition $node) use ($context) {
|
NodeType::VARIABLE_DEFINITION => function(VariableDefinition $node) use ($context) {
|
||||||
$type = Utils\TypeInfo::typeFromAST($context->getSchema(), $node->type);
|
$type = Utils\TypeInfo::typeFromAST($context->getSchema(), $node->type);
|
||||||
|
|
||||||
// If the variable type is not an input type, return an error.
|
// If the variable type is not an input type, return an error.
|
||||||
|
@ -5,6 +5,7 @@ namespace GraphQL\Validator\Rules;
|
|||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\Node;
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Language\AST\Variable;
|
use GraphQL\Language\AST\Variable;
|
||||||
use GraphQL\Language\AST\VariableDefinition;
|
use GraphQL\Language\AST\VariableDefinition;
|
||||||
@ -28,7 +29,7 @@ class VariablesInAllowedPosition
|
|||||||
public function __invoke(ValidationContext $context)
|
public function __invoke(ValidationContext $context)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Node::OPERATION_DEFINITION => [
|
NodeType::OPERATION_DEFINITION => [
|
||||||
'enter' => function () {
|
'enter' => function () {
|
||||||
$this->varDefMap = [];
|
$this->varDefMap = [];
|
||||||
},
|
},
|
||||||
@ -60,7 +61,7 @@ class VariablesInAllowedPosition
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
Node::VARIABLE_DEFINITION => function (VariableDefinition $varDefAST) {
|
NodeType::VARIABLE_DEFINITION => function (VariableDefinition $varDefAST) {
|
||||||
$this->varDefMap[$varDefAST->variable->name->value] = $varDefAST;
|
$this->varDefMap[$varDefAST->variable->name->value] = $varDefAST;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -3,6 +3,7 @@ namespace GraphQL\Validator;
|
|||||||
|
|
||||||
use GraphQL\Language\AST\FragmentSpread;
|
use GraphQL\Language\AST\FragmentSpread;
|
||||||
use GraphQL\Language\AST\HasSelectionSet;
|
use GraphQL\Language\AST\HasSelectionSet;
|
||||||
|
use GraphQL\Language\AST\NodeType;
|
||||||
use GraphQL\Language\AST\OperationDefinition;
|
use GraphQL\Language\AST\OperationDefinition;
|
||||||
use GraphQL\Language\AST\Variable;
|
use GraphQL\Language\AST\Variable;
|
||||||
use GraphQL\Language\Visitor;
|
use GraphQL\Language\Visitor;
|
||||||
@ -132,7 +133,7 @@ class ValidationContext
|
|||||||
if (!$fragments) {
|
if (!$fragments) {
|
||||||
$this->fragments = $fragments =
|
$this->fragments = $fragments =
|
||||||
array_reduce($this->getDocument()->definitions, function($frags, $statement) {
|
array_reduce($this->getDocument()->definitions, function($frags, $statement) {
|
||||||
if ($statement->kind === Node::FRAGMENT_DEFINITION) {
|
if ($statement->kind === NodeType::FRAGMENT_DEFINITION) {
|
||||||
$frags[$statement->name->value] = $statement;
|
$frags[$statement->name->value] = $statement;
|
||||||
}
|
}
|
||||||
return $frags;
|
return $frags;
|
||||||
@ -156,7 +157,7 @@ class ValidationContext
|
|||||||
|
|
||||||
for ($i = 0; $i < count($set->selections); $i++) {
|
for ($i = 0; $i < count($set->selections); $i++) {
|
||||||
$selection = $set->selections[$i];
|
$selection = $set->selections[$i];
|
||||||
if ($selection->kind === Node::FRAGMENT_SPREAD) {
|
if ($selection->kind === NodeType::FRAGMENT_SPREAD) {
|
||||||
$spreads[] = $selection;
|
$spreads[] = $selection;
|
||||||
} else if ($selection->selectionSet) {
|
} else if ($selection->selectionSet) {
|
||||||
$setsToVisit[] = $selection->selectionSet;
|
$setsToVisit[] = $selection->selectionSet;
|
||||||
@ -213,10 +214,10 @@ class ValidationContext
|
|||||||
$newUsages = [];
|
$newUsages = [];
|
||||||
$typeInfo = new TypeInfo($this->schema);
|
$typeInfo = new TypeInfo($this->schema);
|
||||||
Visitor::visit($node, Visitor::visitWithTypeInfo($typeInfo, [
|
Visitor::visit($node, Visitor::visitWithTypeInfo($typeInfo, [
|
||||||
Node::VARIABLE_DEFINITION => function () {
|
NodeType::VARIABLE_DEFINITION => function () {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
Node::VARIABLE => function (Variable $variable) use (&$newUsages, $typeInfo) {
|
NodeType::VARIABLE => function (Variable $variable) use (&$newUsages, $typeInfo) {
|
||||||
$newUsages[] = ['node' => $variable, 'type' => $typeInfo->getInputType()];
|
$newUsages[] = ['node' => $variable, 'type' => $typeInfo->getInputType()];
|
||||||
}
|
}
|
||||||
]));
|
]));
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace GraphQL\Tests\Validator;
|
namespace GraphQL\Tests\Validator;
|
||||||
|
|
||||||
use GraphQL\GraphQL;
|
use GraphQL\GraphQL;
|
||||||
|
use GraphQL\Language\Lexer;
|
||||||
use GraphQL\Language\Parser;
|
use GraphQL\Language\Parser;
|
||||||
use GraphQL\Schema;
|
use GraphQL\Schema;
|
||||||
use GraphQL\Type\Definition\Directive;
|
use GraphQL\Type\Definition\Directive;
|
||||||
@ -308,16 +309,18 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
function expectValid($schema, $rules, $queryString)
|
function expectValid($schema, $rules, $queryString)
|
||||||
{
|
{
|
||||||
|
$parser = new Parser(new Lexer());
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
[],
|
[],
|
||||||
DocumentValidator::validate($schema, Parser::parse($queryString), $rules),
|
DocumentValidator::validate($schema, $parser->parse($queryString), $rules),
|
||||||
'Should validate'
|
'Should validate'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectInvalid($schema, $rules, $queryString, $expectedErrors)
|
function expectInvalid($schema, $rules, $queryString, $expectedErrors)
|
||||||
{
|
{
|
||||||
$errors = DocumentValidator::validate($schema, Parser::parse($queryString), $rules);
|
$parser = new Parser(new Lexer());
|
||||||
|
$errors = DocumentValidator::validate($schema, $parser->parse($queryString), $rules);
|
||||||
|
|
||||||
$this->assertNotEmpty($errors, 'GraphQL should not validate');
|
$this->assertNotEmpty($errors, 'GraphQL should not validate');
|
||||||
$this->assertEquals($expectedErrors, array_map(['GraphQL\Error\Error', 'formatError'], $errors));
|
$this->assertEquals($expectedErrors, array_map(['GraphQL\Error\Error', 'formatError'], $errors));
|
||||||
|
Loading…
Reference in New Issue
Block a user