new Deps
This commit is contained in:
@@ -15,11 +15,12 @@ use GraphQL\Language\AST\NodeKind;
|
||||
use GraphQL\Language\AST\OperationDefinitionNode;
|
||||
use GraphQL\Language\AST\SelectionSetNode;
|
||||
use GraphQL\Language\Visitor;
|
||||
use GraphQL\Language\VisitorOperation;
|
||||
use GraphQL\Type\Definition\Directive;
|
||||
use GraphQL\Type\Definition\FieldDefinition;
|
||||
use GraphQL\Validator\ValidationContext;
|
||||
use function array_map;
|
||||
use function call_user_func_array;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function method_exists;
|
||||
use function sprintf;
|
||||
@@ -60,7 +61,7 @@ class QueryComplexity extends QuerySecurityRule
|
||||
return $this->invokeIfNeeded(
|
||||
$context,
|
||||
[
|
||||
NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) {
|
||||
NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use ($context) : void {
|
||||
$this->fieldNodeAndDefs = $this->collectFieldASTsAndDefs(
|
||||
$context,
|
||||
$context->getParentType(),
|
||||
@@ -69,16 +70,16 @@ class QueryComplexity extends QuerySecurityRule
|
||||
$this->fieldNodeAndDefs
|
||||
);
|
||||
},
|
||||
NodeKind::VARIABLE_DEFINITION => function ($def) {
|
||||
NodeKind::VARIABLE_DEFINITION => function ($def) : VisitorOperation {
|
||||
$this->variableDefs[] = $def;
|
||||
|
||||
return Visitor::skipNode();
|
||||
},
|
||||
NodeKind::OPERATION_DEFINITION => [
|
||||
'leave' => function (OperationDefinitionNode $operationDefinition) use ($context, &$complexity) {
|
||||
'leave' => function (OperationDefinitionNode $operationDefinition) use ($context, &$complexity) : void {
|
||||
$errors = $context->getErrors();
|
||||
|
||||
if (! empty($errors)) {
|
||||
if (count($errors) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,9 +114,8 @@ class QueryComplexity extends QuerySecurityRule
|
||||
|
||||
private function nodeComplexity(Node $node, $complexity = 0)
|
||||
{
|
||||
switch ($node->kind) {
|
||||
case NodeKind::FIELD:
|
||||
/** @var FieldNode $node */
|
||||
switch (true) {
|
||||
case $node instanceof FieldNode:
|
||||
// default values
|
||||
$args = [];
|
||||
$complexityFn = FieldDefinition::DEFAULT_COMPLEXITY_FN;
|
||||
@@ -143,19 +143,17 @@ class QueryComplexity extends QuerySecurityRule
|
||||
}
|
||||
}
|
||||
|
||||
$complexity += call_user_func_array($complexityFn, [$childrenComplexity, $args]);
|
||||
$complexity += $complexityFn($childrenComplexity, $args);
|
||||
break;
|
||||
|
||||
case NodeKind::INLINE_FRAGMENT:
|
||||
/** @var InlineFragmentNode $node */
|
||||
case $node instanceof InlineFragmentNode:
|
||||
// node has children?
|
||||
if (isset($node->selectionSet)) {
|
||||
$complexity = $this->fieldComplexity($node, $complexity);
|
||||
}
|
||||
break;
|
||||
|
||||
case NodeKind::FRAGMENT_SPREAD:
|
||||
/** @var FragmentSpreadNode $node */
|
||||
case $node instanceof FragmentSpreadNode:
|
||||
$fragment = $this->getFragment($node);
|
||||
|
||||
if ($fragment !== null) {
|
||||
@@ -194,7 +192,7 @@ class QueryComplexity extends QuerySecurityRule
|
||||
$this->variableDefs,
|
||||
$this->getRawVariableValues()
|
||||
);
|
||||
if (! empty($errors)) {
|
||||
if (count($errors ?? []) > 0) {
|
||||
throw new Error(implode(
|
||||
"\n\n",
|
||||
array_map(
|
||||
@@ -212,11 +210,16 @@ class QueryComplexity extends QuerySecurityRule
|
||||
|
||||
return ! $directiveArgsIf;
|
||||
}
|
||||
$directive = Directive::skipDirective();
|
||||
$directiveArgsIf = Values::getArgumentValues($directive, $directiveNode, $variableValues);
|
||||
if ($directiveNode->name->value === Directive::SKIP_NAME) {
|
||||
$directive = Directive::skipDirective();
|
||||
/** @var bool $directiveArgsIf */
|
||||
$directiveArgsIf = Values::getArgumentValues($directive, $directiveNode, $variableValues)['if'];
|
||||
|
||||
return $directiveArgsIf['if'];
|
||||
return $directiveArgsIf;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRawVariableValues()
|
||||
@@ -229,7 +232,7 @@ class QueryComplexity extends QuerySecurityRule
|
||||
*/
|
||||
public function setRawVariableValues(?array $rawVariableValues = null)
|
||||
{
|
||||
$this->rawVariableValues = $rawVariableValues ?: [];
|
||||
$this->rawVariableValues = $rawVariableValues ?? [];
|
||||
}
|
||||
|
||||
private function buildFieldArguments(FieldNode $node)
|
||||
@@ -247,7 +250,7 @@ class QueryComplexity extends QuerySecurityRule
|
||||
$rawVariableValues
|
||||
);
|
||||
|
||||
if (! empty($errors)) {
|
||||
if (count($errors ?? []) > 0) {
|
||||
throw new Error(implode(
|
||||
"\n\n",
|
||||
array_map(
|
||||
|
||||
Reference in New Issue
Block a user