You are here

protected function QueryProcessor::validateOperation in GraphQL 8.3

Parameters

\GraphQL\Server\ServerConfig $config:

\GraphQL\Server\OperationParams $params:

\GraphQL\Language\AST\DocumentNode $document:

Return value

\GraphQL\Error\Error[]

Throws

\Exception

1 call to QueryProcessor::validateOperation()
QueryProcessor::doExecuteOperation in src/GraphQL/Execution/QueryProcessor.php

File

src/GraphQL/Execution/QueryProcessor.php, line 344

Class

QueryProcessor

Namespace

Drupal\graphql\GraphQL\Execution

Code

protected function validateOperation(ServerConfig $config, OperationParams $params, DocumentNode $document) {
  $operation = $params->operation;

  // Skip validation if there are no validation rules to be applied.
  if (!($rules = $this
    ->resolveValidationRules($config, $params, $document, $operation))) {
    return [];
  }
  $schema = $config
    ->getSchema();
  $info = new TypeInfo($schema);
  $validation = new ValidationContext($schema, $document, $info);
  $visitors = array_values(array_map(function (AbstractValidationRule $rule) use ($validation, $params) {

    // Set current variable values for QueryComplexity validation rule case
    // @see \GraphQL\GraphQL::promiseToExecute for equivalent
    if ($rule instanceof QueryComplexity && !empty($params->variables)) {
      $rule
        ->setRawVariableValues($params->variables);
    }
    return $rule($validation);
  }, $rules));

  // Run the query visitor with the prepared validation rules and the cache
  // metadata collector and query complexity calculator.
  Visitor::visit($document, Visitor::visitWithTypeInfo($info, Visitor::visitInParallel($visitors)));

  // Return any possible errors collected during validation.
  return $validation
    ->getErrors();
}