A graph type is a reusable schema definition — a list of node types and edge types — that one or more graphs can be instantiated from. Graph types let multiple graphs share the same shape without redeclaring the schema each time.
Graph types are independent objects: dropping a graph type does not affect graphs that were created from it, and conversely.
Show graph types stored in the database:
GQLSHOW GRAPH TYPES
To inspect a single graph type:
GQLDESCRIBE GRAPH TYPE socialType -- DESC is a shorthand for DESCRIBE DESC GRAPH TYPE socialType
Each graph type provides the following essential metadata:
| Field | Description |
|---|---|
name | The unique name assigned to the graph type. |
node_type_count | Number of node types. |
edge_type_count | Number of edge types. |
node_types | Comma-separated list of node type names. |
edge_types | Comma-separated list of edge type names. |
definition | The type definitions. |
bound_graphs | Graphs that use this graph type. |
comment | The comment of the graph type. |
created_at | Creation time. |
updated_at | Last update time. |
Create an empty graph type that schema can be added to later:
GQLCREATE GRAPH TYPE socialType
Create a graph type with an inline specification:
GQLCREATE GRAPH TYPE gType { NODE User ({name STRING, age UINT32}), NODE Club ({name STRING}), EDGE FOLLOWS ()-[{createdOn TIMESTAMP}]->(), EDGE JOINS ()-[]->() }
Create a graph type that is a copy of another graph type:
GQLCREATE GRAPH TYPE socialType AS COPY OF gType
Create a graph type by inferring the schema from an existing graph (the right-hand side is a graph name, not a graph type name). The system reads the labels and properties present in the graph and produces a matching type:
GQLCREATE GRAPH TYPE inferredType LIKE myGraph
When myGraph is an open graph, the inferred type captures only what has actually been inserted — labels seen, and the union of property names and types observed for each label.
You can use the IF NOT EXISTS clause to prevent errors when attempting to create a graph type that already exists. It allows the statement to be safely executed.
GQLCREATE GRAPH TYPE IF NOT EXISTS socialType { NODE Person ({name STRING, email STRING}) }
You can use OR REPLACE to drop the existing graph type with the same name and create a new one in its place:
GQLCREATE OR REPLACE GRAPH TYPE socialType { NODE Person ({name STRING, email STRING}) }
Add node and edge types to a graph type:
GQL-- Add node type Organization to socialType ALTER GRAPH TYPE socialType ADD NODE Organization ({name STRING}) -- Add edge type WorksAt to socialType ALTER GRAPH TYPE socialType ADD EDGE WorksAt (:Person)-[{since DATE}]->(:Organization)
Drop node and edge types from a graph type:
GQL-- Drop node type Organization from socialType ALTER GRAPH TYPE socialType DROP NODE Organization -- Drop edge type WorksAt from socialType ALTER GRAPH TYPE socialType DROP EDGE IF EXISTS WorksAt
Rename socialType to communityType:
GQLALTER GRAPH TYPE socialType RENAME TO communityType
Set comment for communityType:
GQLALTER GRAPH TYPE communityType COMMENT 'Schema for social-network graphs'
Drop the graph type socialType:
GQLDROP GRAPH TYPE socialType
The IF EXISTS clause is used to prevent errors when attempting to delete a graph type that does not exist. It allows the statement to be safely executed.
GQLDROP GRAPH TYPE IF EXISTS socialType
Dropping a graph type does not affect graphs that were already instantiated from it.
Create a graph using a named graph type, see Named Graph Type. The instantiatized graph is a closed graph: inserts must conform to one of the node or edge types defined by the referenced graph type.
NOTEThe link between a closed graph and its graph type is established only at instantiation time where the schema is copied from the type into the graph. After that, the two are independent: subsequent
ALTER GRAPH TYPEchanges do not propagate to graphs already created from it, and the bound graph can independentlyALTER GRAPH ... ADD/DROP NODE/EDGEto evolve its own schema without affecting the type.