diff --git a/docs/schema-graphs.md b/docs/schema-graphs.md index 1b4f2d4..92d2657 100644 --- a/docs/schema-graphs.md +++ b/docs/schema-graphs.md @@ -44,6 +44,13 @@ $arangoClient->schema()->hasGraph('relations'); $arangoClient->schema()->deleteGraph('locations'); ``` +### deleteAllGraphs(): bool +This method deletes all named graphs available on the current database. + +``` +$arangoClient->schema()->deleteAllGraphs(); +``` + ### getGraphVertices(string $name): array ``` $arangoClient->schema()->getGraphVertices('relations'); diff --git a/src/Schema/ManagesGraphs.php b/src/Schema/ManagesGraphs.php index ce090cb..3baf338 100644 --- a/src/Schema/ManagesGraphs.php +++ b/src/Schema/ManagesGraphs.php @@ -92,6 +92,20 @@ public function deleteGraph(string $name): bool return (bool) $this->arangoClient->request('delete', $uri); } + /** + * @throws ArangoException + */ + public function deleteAllGraphs(): bool + { + $graphs = $this->getGraphs(); + + foreach ($graphs as $graph) { + $this->deleteGraph($graph->name); + } + + return true; + } + /** * @see https://www.arangodb.com/docs/stable/http/gharial-management.html#list-vertex-collections * diff --git a/tests/SchemaManagerGraphsTest.php b/tests/SchemaManagerGraphsTest.php index c937f3e..0559eab 100644 --- a/tests/SchemaManagerGraphsTest.php +++ b/tests/SchemaManagerGraphsTest.php @@ -331,3 +331,18 @@ $this->schemaManager->deleteCollection('characters'); $this->schemaManager->deleteCollection('vassals'); }); + +test('deleteAllGraphs', function () { + $result = $this->schemaManager->createGraph('graph1', [], true); + $result = $this->schemaManager->createGraph('graph2', [], true); + + $createdGraphs = $this->schemaManager->getGraphs(); + + $result = $this->schemaManager->deleteAllGraphs(); + + $finalGraphs = $this->schemaManager->getGraphs(); + + expect($result)->toBeTrue(); + expect(count($createdGraphs))->toBe(2); + expect(count($finalGraphs))->toBe(0); +})->only();