public function __invoke(ValidationContext $context)
{
$this->context = $context;
$this->variableDefs = new \ArrayObject();
$this->fieldNodeAndDefs = new \ArrayObject();
$complexity = 0;
return $this->invokeIfNeeded($context, [NodeKind::SELECTION_SET => function (SelectionSetNode $selectionSet) use($context) {
$this->fieldNodeAndDefs = $this->collectFieldASTsAndDefs($context, $context->getParentType(), $selectionSet, null, $this->fieldNodeAndDefs);
}, NodeKind::VARIABLE_DEFINITION => function ($def) {
$this->variableDefs[] = $def;
return Visitor::skipNode();
}, NodeKind::OPERATION_DEFINITION => ['leave' => function (OperationDefinitionNode $operationDefinition) use($context, &$complexity) {
$complexity = $this->fieldComplexity($operationDefinition, $complexity);
if ($complexity > $this->getMaxQueryComplexity()) {
$context->reportError(new Error($this->maxQueryComplexityErrorMessage($this->getMaxQueryComplexity(), $complexity)));
}
}]]);
}