Graph functions

graph.names()

Details

Syntax

graph.names()

Description

Lists the names of graphs in the current database.

Returns

LIST<STRING>

Considerations

graph.names() is only supported on composite databases.

Example 1. graph.names()
Setup
CREATE DATABASE dba;
CREATE DATABASE dbb;
CREATE DATABASE dbc;
CREATE COMPOSITE DATABASE composite;
CREATE ALIAS composite.first FOR DATABASE dba;
CREATE ALIAS composite.second FOR DATABASE dbb;
CREATE ALIAS composite.third FOR DATABASE dbc;
Query
RETURN graph.names() AS name

The names of all graphs on the current composite database are returned.

Result
name

"composite.first"

"composite.second"

"composite.third"

Rows: 3

graph.propertiesByName()

Details

Syntax

graph.propertiesByName(graphName)

Description

Returns the MAP of properties associated with a graph.

Arguments

Name

Type

Description

graphName

STRING

The name of the graph from which all associated properties will be returned.

Returns

MAP

Considerations

graph.propertiesByName() is only supported on composite databases.

The properties in the returned MAP are set on the aliasthat adds the graph as a constituent of a composite database.

Example 2. graph.propertiesByName()
Setup
CREATE DATABASE dba;
CREATE DATABASE dbb;
CREATE DATABASE dbc;
CREATE COMPOSITE DATABASE composite;
CREATE ALIAS composite.first FOR DATABASE dba
  PROPERTIES {number: 1, tags: ['A', 'B']};
CREATE ALIAS composite.second FOR DATABASE dbb
  PROPERTIES {number: 0, tags: ['A']};
CREATE ALIAS composite.third FOR DATABASE dbc
  PROPERTIES {number: 2, tags: ['B', 'C']};
Query
UNWIND graph.names() AS name
RETURN name, graph.propertiesByName(name) AS props

Properties for all graphs on the current composite database are returned.

Result
name props

"composite.first"

{number: 1, tags: ["A", "B"]}

"composite.second"

{number: 0, tags: ["A"]}

"composite.third"

{number: 2, tags: ["B", "C"]}

Rows: 3

Query
UNWIND graph.names() AS name
WITH name, graph.propertiesByName(name) AS props
WHERE "A" IN props.tags
CALL () {
  USE graph.byName(name)
  MATCH (n)
  RETURN n
}
RETURN n

Returns all nodes from a subset of graphs that have a tags property containing "A".

The above query uses an empty variable scope clause: CALL () { …​ } (introduced in Neo4j 5.23). If you are using an older version of Neo4j, use CALL { …​ } instead. For more information, see CALL subqueries → Importing variables.

graph.byName()

Details

Syntax

graph.byName(name)

Description

Returns the graph reference of the given name. It is only supported in the USE clause, on composite databases.

Arguments

Name

Type

Description

name

STRING

The name of the graph to be resolved.

Returns

GRAPH

Example 3. graph.byName()
Query
UNWIND graph.names() AS graphName
CALL () {
  USE graph.byName(graphName)
  MATCH (n)
  RETURN n
}
RETURN n

Returns all nodes from all graphs on the current composite database.

The above query uses an empty variable scope clause: CALL () { …​ } (introduced in Neo4j 5.23). If you are using an older version of Neo4j, use CALL { …​ } instead. For more information, see CALL subqueries → Importing variables.

graph.byElementId()

Details

Syntax

graph.byElementId(elementId)

Description

Returns the graph reference with the given element id. It is only supported in the USE clause, on composite databases.

Arguments

Name

Type

Description

elementId

STRING

An element id of a node or relationship.

Returns

GRAPH

Considerations

If the constituent database is not a standard database in the DBMS, an error will be thrown.

Example 4. graph.byElementId()

In this example, it is assumed that the DBMS contains a composite database constituent, which contains the element id 4:c0a65d96-4993-4b0c-b036-e7ebd9174905:0.

Query
USE graph.byElementId("4:c0a65d96-4993-4b0c-b036-e7ebd9174905:0")
MATCH (n) RETURN n