public function saveEdge($collection, $from, $to, $document, array $options = [])
    {
        $collection = $this->makeCollection($collection);

        if (is_array($document)) {
            $_edgeClass = $this->_edgeClass;
            $document = $_edgeClass::createFromArray($document);
        }
        $document->setFrom($from);
        $document->setTo($to);

        $params = $this->includeOptionsInParams(
            $options, [
                'waitForSync'      => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
                'createCollection' => $this->getConnectionOption(ConnectionOptions::OPTION_CREATE)
            ]
        );

        $this->createCollectionIfOptions($collection, $params);

        $data = $document->getAllForInsertUpdate();

        $url      = UrlHelper::appendParamsUrl(Urls::URL_EDGE . '/' . $collection, $params);
        $response = $this->getConnection()->post($url, $this->json_encode_wrapper($data));

        $location = $response->getLocationHeader();
        if (!$location) {
            throw new ClientException('Did not find location header in server response');
        }

        $json = $response->getJson();
        $id   = UrlHelper::getDocumentIdFromLocation($location);

        $document->setInternalId($json[Edge::ENTRY_ID]);
        $document->setRevision($json[Edge::ENTRY_REV]);

        if ($id !== $document->getId()) {
            throw new ClientException('Got an invalid response from the server');
        }

        $document->setIsNew(false);

        return $document->getId();
    }