A closed graph is constrained by its graph type, which is a list of node types and edge types. It imposes a strict framework that governs data insertion: each node or edge belongs to exactly one node type or edge type. The graph type ensures consistent structure and guarantees high data integrity and consistency.
In a closed graph,
Syntax<create closed graph statement> ::= "CREATE GRAPH" [ "IF NOT EXISTS" ] { <inline graph type> | <named graph type> | <inferred graph type> }
You have three ways to create a closed graph:
Define the node and edge types directly in the CREATE GRAPH statement. The graph type lives on the graph itself, with no separate named definition.
Syntax<inline graph type> ::= "{" [ <element type> [ { "," <element type> }... ] ] "}" <element type> = <node type> | <edge type> <node type> ::= "NODE" [ "TYPE" ] <node type name> "(" [ <additional labels> ] [ <property types> ] ")" <edge type> ::= "EDGE" [ "TYPE" ] <edge type name> <source node type> "-[" [ <additional labels> ] [ <property types> ] "]->" <destination node type> <source/destination node type> ::= "(" [ ":" <label name> [ { "&" <label name> } ... ] ] ")" <additional labels> ::= ":" <label name> [ { "&" <label name> } ... ] <property types> ::= "{" <property type> [ { "," <property type> } ... ] "}" <property type> ::= <property name> <property value type> [ <constraint type> ]
Create a closed graph g2 with inline graph type specification:
GQLCREATE GRAPH g2 { NODE User ({name STRING, age UINT32}), NODE Club ({name STRING}), EDGE FOLLOWS ()-[{createdOn TIMESTAMP}]->(), EDGE JOINS ()-[]->() }
The node or edge type name automatically becomes a label. The label set of a node or edge type is the union of its type name and optional additional labels.
When no additional labels are specified, the type name is the only label:
GQL-- label set: [User] NODE User ({name STRING})
Add additional labels:
GQL-- label set: [User, Employee] NODE User (:Employee {name STRING}) -- label set: [User, Employee, Manager] NODE User (:Employee&Manager {name STRING})
Edge types can specify source and destination node types, where <source/destination node type> is () or (<labels>). The <labels> is matched against the label sets of node types.
GQL-- The FOLLOWS edge connects any two nodes EDGE FOLLOWS ()-[{createdOn LOCAL DATETIME}]->() -- The JOINS edge connects source nodes whose label set is [User,Employee] to destination nodes whose label set is [Company] EDGE JOINS (:User&Employee)-[{title STRING}]->(:Company)
Each node or edge type is associated with a set property types. Each property type is defined with a property value type.
Bind the graph to a pre-defined, reusable graph type. The graph type lives as a separate object and can be shared by multiple graphs.
Syntax<named graph type> ::= [ "::" | "TYPED" ] <graph type name>
Create a closed graph g3 with all the node and edge types and properties defined within the graph type gType:
GQL-- Bare reference CREATE GRAPH g3 gType -- :: separator CREATE GRAPH g3 :: gType -- TYPED keyword CREATE GRAPH g3 TYPED gType
Copy the graph type from another closed graph. Only the schema (node and edge types) is copied, no data is included.
Syntax<cloned graph type> ::= "LIKE" <graph name>
Create a closed graph g4 whose schema matches g2:
GQLCREATE GRAPH g4 LIKE g2
To clone both the schema and the data, use AS COPY OF instead (see Cloning Graphs).
Show node or edge types defined in the current graph:
GQLSHOW NODE TYPES SHOW EDGE TYPES
To inspect a single node or edge type:
GQLDESCRIBE NODE TYPE Person DESCRIBE EDGE TYPE Follows -- DESC is a shorthand for DESCRIBE DESC NODE TYPE Person DESC EDGE TYPE Follows
Each type provides the following metadata:
| Field | Description |
|---|---|
type | NODE or EDGE. |
name | The name of the type. |
properties | The associated property definitions. |
Show labels in the current graph:
GQLSHOW LABELS SHOW NODE LABELS SHOW EDGE LABELS
To inspect a single label:
GQLDESCRIBE LABEL myLabel -- DESC is a shorthand for DESCRIBE DESC LABEL myLabel
Each label provides the following essential metadata:
| Field | Description |
|---|---|
label | The name of the label. |
type | The type of the label, NODE or EDGE. |
Add node and edge types to a closed graph:
GQL-- Add node type Book to g2 ALTER GRAPH g2 ADD NODE Book ({name STRING, author STRING}) -- Add edge type PURCHASED to g2 ALTER GRAPH g2 ADD EDGE PURCHASED (:User)-[{createdOn TIMESTAMP}]->(:Book)
Add properties to node and edge types in the current graph:
GQL-- Add property gender to node type User ALTER NODE User ADD PROPERTY gender STRING -- Add property memberNo to edge type JOINS ALTER EDGE JOINS ADD PROPERTY memberNo INT32
Rename node and edge types in the current graph:
GQL-- Rename node type User to People ALTER NODE User RENAME TO People -- Rename edge type FOLLOWS to LINKS ALTER EDGE FOLLOWS RENAME TO LINKS
Rename node and edge properties in the current graph:
GQL-- Rename property name to title for Book node type ALTER NODE Book PROPERTY name RENAME TO title -- Rename property memberNo to memberNumber for JOINS edge type ALTER EDGE JOINS PROPERTY memberNo RENAME TO memberNumber
A node or edge type can only be dropped when no nodes or edges of that type exist. Drop node and edge types from a graph:
GQL-- Drop node type User from g2 ALTER GRAPH g2 DROP NODE User -- Drop edge type FOLLOWS from g2 ALTER GRAPH g2 DROP EDGE FOLLOWS
When a property is dropped, all related data - including the property values, associated indexes, and cached values - is permanently removed. Drop node and edge properties from the current graph:
GQL-- Drop property name from node type User ALTER NODE User DROP PROPERTY name -- Drop property createdOn from edge type FOLLOWS ALTER EDGE FOLLOWS DROP PROPERTY createdOn