for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*******************************************************************************
* This file is part of the GraphQL Bundle package.
*
* (c) YnloUltratech <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
******************************************************************************/
namespace Ynlo\GraphQLBundle\Util;
use GraphQL\Type\Definition\Type;
/**
* Util to work with GraphQL types
*/
final class TypeUtil
{
* @param string $type
* @return bool
public static function isTypeList($type): bool
return (bool) preg_match('/^\[([\\\\\w]+)!?\]!?$/', $type);
}
public static function isTypeNonNullList($type): bool
return (bool) preg_match('/^\[([\\\\\w]+)!\]!?$/', $type);
public static function isTypeNonNull($type): bool
return (bool) preg_match('/!$/', $type);
* @return string
public static function normalize($type)
if (preg_match('/^\[?([\\\\\w]+)!?\]?!?$/', $type, $matches)) {
$type = $matches[1];
switch ($type) {
case 'bool':
case 'boolean':
$type = Type::BOOLEAN;
break;
case 'decimal':
case 'float':
$type = Type::FLOAT;
case 'int':
case 'integer':
$type = Type::INT;
case 'string':
$type = Type::STRING;
case 'id':
$type = Type::ID;
case 'datetime':
case 'date_time':
case 'date':
$type = 'DateTime';
return $type;