for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Digia\Lumen\GraphQL\Fields;
use Digia\Lumen\GraphQL\Exceptions\MalformedNodeIdException;
class NodeIdResolver
{
private const INDEX_TYPE = 0;
private const INDEX_ID = 1;
/**
* @param string $globalId
*
* @return string
* @throws MalformedNodeIdException
*/
public static function typeFromGlobalId(string $globalId): string
return self::fromGlobalId($globalId)[self::INDEX_TYPE];
}
public static function idFromGlobalId(string $globalId): string
return self::fromGlobalId($globalId)[self::INDEX_ID];
* @param string $typeName
* @param string $id
public static function toGlobalId(string $typeName, string $id): string
return base64_encode(implode(':', [$typeName, $id]));
* @return array
protected static function fromGlobalId(string $globalId): array
$decodedGlobalId = base64_decode($globalId);
if (strpos($decodedGlobalId, ':') === false) {
throw new MalformedNodeIdException(sprintf('Node ID "%s" is malformed.', $globalId));
return explode(':', $decodedGlobalId);