Inheritance: extends Youshido\GraphQL\Parser\Ast\Interfaces\LocatableInterface
示例#1
0
 public function assertValidArguments(FieldInterface $field, AstFieldInterface $query, Request $request)
 {
     $requiredArguments = array_filter($field->getArguments(), function (InputField $argument) {
         return $argument->getType()->getKind() == TypeMap::KIND_NON_NULL;
     });
     foreach ($query->getArguments() as $astArgument) {
         if (!$field->hasArgument($astArgument->getName())) {
             throw new ResolveException(sprintf('Unknown argument "%s" on field "%s"', $astArgument->getName(), $field->getName()), $astArgument->getLocation());
         }
         $argument = $field->getArgument($astArgument->getName());
         $argumentType = $argument->getType()->getNullableType();
         switch ($argumentType->getKind()) {
             case TypeMap::KIND_ENUM:
             case TypeMap::KIND_SCALAR:
             case TypeMap::KIND_INPUT_OBJECT:
             case TypeMap::KIND_LIST:
                 if (!$argument->getType()->isValidValue($argumentType->parseValue($astArgument->getValue()))) {
                     throw new ResolveException(sprintf('Not valid type for argument "%s" in query "%s"', $astArgument->getName(), $field->getName()), $astArgument->getLocation());
                 }
                 break;
             default:
                 throw new ResolveException(sprintf('Invalid argument type "%s"', $argumentType->getName()));
         }
         if (array_key_exists($astArgument->getName(), $requiredArguments) || $argument->getConfig()->get('default') !== null) {
             unset($requiredArguments[$astArgument->getName()]);
         }
     }
     if (count($requiredArguments)) {
         throw new ResolveException(sprintf('Require "%s" arguments to query "%s"', implode(', ', array_keys($requiredArguments)), $query->getName()));
     }
 }
示例#2
0
 private function getAlias(AstFieldInterface $ast)
 {
     return $ast->getAlias() ?: $ast->getName();
 }