示例#1
0
 /**
  * {@inheritdoc}
  */
 public function coerceLiteral(Node $node)
 {
     if ($node instanceof StringValue || $node instanceof IntValue) {
         return $node->get('value');
     }
     return NULL;
 }
示例#2
0
 /**
  * @param \Fubhy\GraphQL\Language\Node $value
  *
  * @return string|null
  */
 public function coerceLiteral(Node $value)
 {
     if ($value instanceof EnumValue) {
         $key = $value->get('value');
         if (($lookup = $this->getNameLookup()) && isset($lookup[$key])) {
             return $lookup[$key] ? $lookup[$key]->getName() : NULL;
         }
     }
     return NULL;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function coerceLiteral(Node $node)
 {
     if ($node instanceof IntValue || $node instanceof FloatValue) {
         $num = (double) $node->get('value');
         if ($num <= PHP_INT_MAX && $num >= -PHP_INT_MAX) {
             return $num;
         }
     }
     return NULL;
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function coerceLiteral(Node $node)
 {
     if ($node instanceof IntValue) {
         $num = $node->get('value');
         if ($num <= PHP_INT_MAX && $num >= -PHP_INT_MAX) {
             return intval($num);
         }
     }
     return NULL;
 }
示例#5
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\TypeInterface $type
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(TypeInterface $type, Location $location = NULL)
 {
     if (!($type instanceof NamedType || $type instanceof ListType)) {
         throw new \InvalidArgumentException(sprintf('Invalid type %s.', get_class($type)));
     }
     parent::__construct($location, ['type' => $type]);
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function coerceLiteral(Node $node)
 {
     return $node instanceof StringValue ? $node->get('value') : NULL;
 }
示例#7
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\Variable $variable
  * @param \Fubhy\GraphQL\Language\Node\TypeInterface $type
  * @param \Fubhy\GraphQL\Language\Node\ValueInterface $defaultValue
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(Variable $variable, TypeInterface $type, ValueInterface $defaultValue = NULL, Location $location = NULL)
 {
     parent::__construct($location, ['variable' => $variable, 'type' => $type, 'defaultValue' => $defaultValue]);
 }
示例#8
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\TypeInterface $type
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(TypeInterface $type, Location $location = NULL)
 {
     parent::__construct($location, ['type' => $type]);
 }
示例#9
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\SelectionInterface[] $selections
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(array $selections, Location $location = NULL)
 {
     parent::__construct($location, ['selections' => $selections]);
 }
示例#10
0
 /**
  * Constructor.
  *
  * @param string $operation
  * @param \Fubhy\GraphQL\Language\Node\Name $name
  * @param \Fubhy\GraphQL\Language\Node\VariableDefinition[] $variableDefinitions
  * @param \Fubhy\GraphQL\Language\Node\Directive[] $directives
  * @param \Fubhy\GraphQL\Language\Node\SelectionSet $selectionSet
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct($operation, Name $name = NULL, array $variableDefinitions = [], array $directives = [], SelectionSet $selectionSet, Location $location = NULL)
 {
     parent::__construct($location, ['operation' => $operation, 'name' => $name, 'variableDefinitions' => $variableDefinitions, 'directives' => $directives, 'selectionSet' => $selectionSet]);
 }
示例#11
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\ValueInterface[] $values
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(array $values, Location $location = NULL)
 {
     parent::__construct($location, ['values' => $values]);
 }
示例#12
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\Name $name
  * @param \Fubhy\GraphQL\Language\Node\ValueInterface $value
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(Name $name, ValueInterface $value, Location $location = NULL)
 {
     parent::__construct($location, ['name' => $name, 'value' => $value]);
 }
示例#13
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\Name $name
  * @param \Fubhy\GraphQL\Language\Node\Directive[] $directives
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(Name $name, array $directives = [], Location $location = NULL)
 {
     parent::__construct($location, ['name' => $name, 'directives' => $directives]);
 }
示例#14
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Location $location
  * @param \Fubhy\GraphQL\Language\Node\DefinitionInterface[] $definitions
  */
 public function __construct(array $definitions, Location $location = NULL)
 {
     parent::__construct($location, ['definitions' => $definitions]);
 }
示例#15
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\Name $name
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(Name $name = NULL, Location $location = NULL)
 {
     parent::__construct($location, ['name' => $name]);
 }
示例#16
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\NamedType $typeCondition
  * @param \Fubhy\GraphQL\Language\Node\Directive[] $directives
  * @param \Fubhy\GraphQL\Language\Node\SelectionSet $selectionSet
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(NamedType $typeCondition, array $directives = [], SelectionSet $selectionSet, Location $location = NULL)
 {
     parent::__construct($location, ['typeCondition' => $typeCondition, 'directives' => $directives, 'selectionSet' => $selectionSet]);
 }
示例#17
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\ObjectField[] $fields
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(array $fields, Location $location = NULL)
 {
     parent::__construct($location, ['fields' => $fields]);
 }
示例#18
0
 /**
  * Constructor.
  *
  * @param string $value
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct($value, Location $location = NULL)
 {
     parent::__construct($location, ['value' => $value]);
 }
示例#19
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\Name $name
  * @param \Fubhy\GraphQL\Language\Node\Argument[] $arguments
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(Name $name, array $arguments = NULL, Location $location = NULL)
 {
     parent::__construct($location, ['name' => $name, 'arguments' => $arguments]);
 }
示例#20
0
 /**
  * @param Node $node
  */
 protected function enter(Node $node)
 {
     $schema = $this->_schema;
     switch ($node::KIND) {
         case Node::KIND_SELECTION_SET:
             $rawType = $this->getType();
             $rawType = isset($rawType) ? $rawType->getUnmodifiedType() : NULL;
             $compositeType = NULL;
             if (isset($rawType) && $rawType->isCompositeType()) {
                 $compositeType = $rawType;
             }
             array_push($this->parentTypeStack, $compositeType);
             break;
         case Node::KIND_DIRECTIVE:
             $this->directive = $schema->getDirective($node->get('name')->get('value'));
             break;
         case Node::KIND_FIELD:
             $parentType = $this->getParentType();
             $fieldDefinition = NULL;
             if (isset($parentType)) {
                 $fieldDefinition = self::getFieldDefinition($schema, $parentType, $node);
             }
             array_push($this->fieldDefinitionStack, $fieldDefinition);
             array_push($this->typeStack, $fieldDefinition ? $fieldDefinition->getType() : NULL);
             break;
         case Node::KIND_OPERATION_DEFINITION:
             $type = NULL;
             if ($node->get('operation') === 'query') {
                 $type = $schema->getQueryType();
             } else {
                 if ($node->get('operation') === 'mutation') {
                     $type = $schema->getMutationType();
                 }
             }
             array_push($this->typeStack, $type);
             break;
         case Node::KIND_INLINE_FRAGMENT:
         case Node::KIND_FRAGMENT_DEFINITION:
             $type = $schema->getType($node->get('typeCondition')->get('value'));
             array_push($this->typeStack, $type);
             break;
         case Node::KIND_VARIABLE_DEFINITION:
             array_push($this->inputTypeStack, self::typeFromAST($schema, $node->get('type')));
             break;
         case Node::KIND_ARGUMENT:
             if (!empty($this->fieldDefinitionStack)) {
                 $field = $this->fieldDefinitionStack[count($this->fieldDefinitionStack) - 1];
             } else {
                 $field = NULL;
             }
             $argType = NULL;
             if ($field) {
                 $argDefinition = NULL;
                 foreach ($field->getArguments() as $arg) {
                     if ($arg->getName() === $node->get('name')->get('value')) {
                         $argDefinition = $arg;
                     }
                     break;
                 }
                 if ($argDefinition) {
                     $argType = $argDefinition->getType();
                 }
             }
             array_push($this->inputTypeStack, $argType);
             break;
         case Node::KIND_ARRAY_VALUE:
             $arrayType = $this->getInputType();
             $arrayType = isset($arrayType) ? $arrayType->getNullableType() : NULL;
             array_push($this->inputTypeStack, $arrayType instanceof ListModifier ? $arrayType->getWrappedType() : NULL);
             break;
         case Node::KIND_OBJECT_FIELD:
             $objectType = $this->getInputType();
             $objectType = isset($objectType) ? $objectType->getUnmodifiedType() : NULL;
             $fieldType = NULL;
             if ($objectType instanceof InputObjectType) {
                 $tmp = $objectType->getFields();
                 $inputField = isset($tmp[$node->get('name')->get('value')]) ? $tmp[$node->get('name')->get('value')] : NULL;
                 $fieldType = $inputField ? $inputField->getType() : NULL;
             }
             array_push($this->inputTypeStack, $fieldType);
             break;
     }
 }
示例#21
0
 /**
  * Constructor.
  *
  * @param \Fubhy\GraphQL\Language\Node\Name $name
  * @param \Fubhy\GraphQL\Language\Node\Name $alias
  * @param \Fubhy\GraphQL\Language\Node\Argument[] $arguments
  * @param \Fubhy\GraphQL\Language\Node\Directive[] $directives
  * @param \Fubhy\GraphQL\Language\Node\SelectionSet $selectionSet
  * @param \Fubhy\GraphQL\Language\Location $location
  */
 public function __construct(Name $name, Name $alias = NULL, array $arguments = [], array $directives = [], SelectionSet $selectionSet = NULL, Location $location = NULL)
 {
     parent::__construct($location, ['name' => $name, 'alias' => $alias, 'arguments' => $arguments, 'directives' => $directives, 'selectionSet' => $selectionSet]);
 }