isScalarType() public static method

public static isScalarType ( $type )
Example #1
0
 /**
  * NonNullType constructor.
  *
  * @param AbstractType|string $fieldType
  *
  * @throws ConfigurationException
  */
 public function __construct($fieldType)
 {
     if (!TypeService::isGraphQLType($fieldType)) {
         throw new ConfigurationException('NonNullType accepts only GraphpQL Types as argument');
     }
     if (TypeService::isScalarType($fieldType)) {
         $fieldType = TypeFactory::getScalarType($fieldType);
     }
     $this->_typeOf = $fieldType;
 }
Example #2
0
 public function testTypeService()
 {
     $this->assertTrue(TypeService::isScalarType(TypeMap::TYPE_STRING));
     $this->assertFalse(TypeService::isScalarType('gibberish'));
     $this->assertFalse(TypeService::isScalarType(new TestObjectType()));
     $stringType = new StringType();
     $this->assertFalse(TypeService::isInterface($stringType));
     $this->assertEquals(TypeService::resolveNamedType($stringType), $stringType);
     $this->assertNull(TypeService::resolveNamedType(null));
     $this->assertEquals(TypeService::resolveNamedType(123), $stringType);
 }
Example #3
0
 public function __construct(array $config = [])
 {
     if (empty($config['type'])) {
         $config['type'] = $this->getType();
         $config['name'] = $this->getName();
     }
     if (TypeService::isScalarType($config['type'])) {
         $config['type'] = TypeFactory::getScalarType($config['type']);
     }
     $this->config = new InputFieldConfig($config, $this, $this->isFinal);
     $this->build($this->config);
 }
Example #4
0
 /**
  * @param string $type
  *
  * @throws ConfigurationException
  * @return AbstractScalarType
  */
 public static function getScalarType($type)
 {
     if (TypeService::isScalarType($type)) {
         if (is_object($type)) {
             $typeName = $type->getName();
             if (empty(self::$objectsHash[$typeName])) {
                 self::$objectsHash[$typeName] = $type;
             }
             return self::$objectsHash[$typeName];
         }
         if (empty(self::$objectsHash[$type])) {
             $name = ucfirst($type);
             $name = $name == 'Datetime' ? 'DateTime' : $name;
             $name = $name == 'Datetimetz' ? 'DateTimeTz' : $name;
             $className = 'Youshido\\GraphQL\\Type\\Scalar\\' . $name . 'Type';
             self::$objectsHash[$type] = new $className();
         }
         return self::$objectsHash[$type];
     } else {
         throw new ConfigurationException('Configuration problem with type ' . $type);
     }
 }
Example #5
0
 /**
  * @param mixed|AbstractType $type
  * @return bool
  */
 public static function isInputType($type)
 {
     if (is_object($type)) {
         $namedType = $type->getNullableType()->getNamedType();
         return $namedType instanceof AbstractScalarType || $type instanceof AbstractListType || $namedType instanceof AbstractInputObjectType || $namedType instanceof AbstractEnumType;
     } else {
         return TypeService::isScalarType($type);
     }
 }