Check if a graph exists
We can check if a graph is stored in the catalog by looking up its name.
Syntax
CALL gds.graph.exists(graphName: String) YIELD
graphName: String,
exists: Boolean
Name | Type | Optional | Description |
---|---|---|---|
graphName |
String |
no |
The name under which the graph is stored in the catalog. |
Name | Type | Description |
---|---|---|
|
String |
Name of the removed graph. |
|
Boolean |
If the graph exists in the graph catalog. |
Additionally, to the procedure, we provide a function which directly returns the exists field from the procedure.
RETURN gds.graph.exists(graphName: String)::Boolean
Examples
All the examples below should be run in an empty database. The examples use Cypher projections as the norm. Native projections will be deprecated in a future release. |
In order to demonstrate the GDS Graph Exists capabilities we are going to create a small social network graph in Neo4j and project it into our graph catalog.
CREATE
(florentin:Person { name: 'Florentin', age: 16 }),
(adam:Person { name: 'Adam', age: 18 }),
(veselin:Person { name: 'Veselin', age: 20 }),
(florentin)-[:KNOWS { since: 2010 }]->(adam),
(florentin)-[:KNOWS { since: 2018 }]->(veselin)
Person
nodes and KNOWS
relationships:MATCH (n:Person)-[r:KNOWS]->(m:Person)
RETURN gds.graph.project('persons', n, m)
Procedure
UNWIND ['persons', 'books'] AS graph
CALL gds.graph.exists(graph)
YIELD graphName, exists
RETURN graphName, exists
graphName | exists |
---|---|
"persons" |
true |
"books" |
false |
We can verify the projected persons
graph exists while a books
graph does not.
Function
As an alternative to the procedure, we can also use the corresponding function.
Unlike procedures, functions can be inlined in other cypher-statements such as RETURN
or WHERE
.
RETURN gds.graph.exists('persons') AS personsExists, gds.graph.exists('books') AS booksExists
personsExists | booksExists |
---|---|
true |
false |
As before, we can verify the projected persons
graph exists while a books
graph does not.