misplacedDirectiveMessage() static public method

static public misplacedDirectiveMessage ( $directiveName, $placement )
Exemplo n.º 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) {
             return new Error(Messages::unknownDirectiveMessage($node->name->value), [$node]);
         }
         $appliedTo = $ancestors[count($ancestors) - 1];
         if ($appliedTo instanceof OperationDefinition && !$directiveDef->onOperation) {
             return new Error(Messages::misplacedDirectiveMessage($node->name->value, 'operation'), [$node]);
         }
         if ($appliedTo instanceof Field && !$directiveDef->onField) {
             return new Error(Messages::misplacedDirectiveMessage($node->name->value, 'field'), [$node]);
         }
         $fragmentKind = $appliedTo instanceof FragmentSpread || $appliedTo instanceof InlineFragment || $appliedTo instanceof FragmentDefinition;
         if ($fragmentKind && !$directiveDef->onFragment) {
             return new Error(Messages::misplacedDirectiveMessage($node->name->value, 'fragment'), [$node]);
         }
     }];
 }
Exemplo n.º 2
0
 function misplacedDirective($directiveName, $placement, $line, $column)
 {
     return new FormattedError(Messages::misplacedDirectiveMessage($directiveName, $placement), [new SourceLocation($line, $column)]);
 }