GraphQL\Validator\ValidationContext::reportError PHP Method

reportError() public method

public reportError ( Error $error )
$error GraphQL\Error\Error
    function reportError(Error $error)
    {
        $this->errors[] = $error;
    }

Usage Example

Beispiel #1
0
 public function __invoke(ValidationContext $context)
 {
     return [Node::DIRECTIVE => function (Directive $node, $key, $parent, $path, $ancestors) use($context) {
         $directiveDef = null;
         foreach ($context->getSchema()->getDirectives() as $def) {
             if ($def->name === $node->name->value) {
                 $directiveDef = $def;
                 break;
             }
         }
         if (!$directiveDef) {
             $context->reportError(new Error(self::unknownDirectiveMessage($node->name->value), [$node]));
             return;
         }
         $appliedTo = $ancestors[count($ancestors) - 1];
         $candidateLocation = $this->getLocationForAppliedNode($appliedTo);
         if (!$candidateLocation) {
             $context->reportError(new Error(self::misplacedDirectiveMessage($node->name->value, $node->type), [$node]));
         } else {
             if (!in_array($candidateLocation, $directiveDef->locations)) {
                 $context->reportError(new Error(self::misplacedDirectiveMessage($node->name->value, $candidateLocation), [$node]));
             }
         }
     }];
 }
All Usage Examples Of GraphQL\Validator\ValidationContext::reportError