diff --git a/Relay/Node/GlobalId.php b/Relay/Node/GlobalId.php index f91b28327..03a096575 100644 --- a/Relay/Node/GlobalId.php +++ b/Relay/Node/GlobalId.php @@ -22,13 +22,19 @@ public static function toGlobalId($type, $id) public static function fromGlobalId($globalId) { - $unBasedGlobalId = base64_decode($globalId); + $unBasedGlobalId = base64_decode($globalId, true); - list($type, $id) = array_merge(explode(static::SEPARATOR, $unBasedGlobalId), [true]); - - return [ - 'type' => $type, - 'id' => $id, + $decodeGlobalId = [ + 'type' => null, + 'id' => null, ]; + + if (!$unBasedGlobalId) { + return $decodeGlobalId; + } + + list($decodeGlobalId['type'], $decodeGlobalId['id']) = array_pad(explode(static::SEPARATOR, $unBasedGlobalId), 2, null); + + return $decodeGlobalId; } } diff --git a/Tests/Relay/Node/GlobalIdTest.php b/Tests/Relay/Node/GlobalIdTest.php index e0dcb5342..52c2ac7bb 100644 --- a/Tests/Relay/Node/GlobalIdTest.php +++ b/Tests/Relay/Node/GlobalIdTest.php @@ -70,4 +70,11 @@ public function testFromGlobalIdWithTypeAndIdEmpty() $this->assertEquals(['type' => null, 'id' => null], $params); } + + public function testFromGlobalIdWithNotBase64Entry() + { + $params = GlobalId::fromGlobalId(1); + + $this->assertEquals(['type' => null, 'id' => null], $params); + } }