UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Questioned Paths
    • Shortest Paths
    • Cheapest Paths
    • K-Hop Traversal
    • Graph Patterns
    • Overview
    • Open Graphs
    • Closed Graphs
    • Graph Types
    • Constraints
    • Projections
    • Storage Maintenance
    • Node and Edge IDs
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • MERGE
    • SET
    • REMOVE
    • DELETE
    • FOREACH
    • LOAD CSV
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Element Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Null Functions
    • Utility Functions
    • Type Conversion Functions
    • Table Functions
  • Operators
  • Predicates
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Expressions
    • Current Values
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Execution Plan
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Naming Conventions
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Graph Management

Graph Types

NOTE

Scope of this page. This page covers named graph types, the catalog objects created via CREATE GRAPH TYPE.

The inline (CREATE GRAPH <graph> { … }), LIKE, and AS COPY OF forms produce closed graphs whose graph type is embedded directly in the graph, they do not create a named graph type. For those, see Closed Graphs.

Overview

A graph type is a named, reusable schema definition, including a list of node types and edge types. Named graph types let multiple graphs share the same shape without redeclaring the schema each time.

Showing Graph Types

Show graph types stored in the database:

GQL
SHOW GRAPH TYPES

To inspect a single graph type:

GQL
DESCRIBE GRAPH TYPE socialType

-- DESC is a shorthand for DESCRIBE
DESC GRAPH TYPE socialType

Each graph type provides the following essential metadata:

FieldDescription
nameThe unique name assigned to the graph type.
node_type_countNumber of node types.
edge_type_countNumber of edge types.
node_typesComma-separated list of node type names.
edge_typesComma-separated list of edge type names.
definitionThe type definitions.
bound_graphsGraphs that use this graph type.
commentThe comment of the graph type.
created_atCreation time.
updated_atLast update time.

Creating Graph Types

You have three ways to create a graph type:

Syntax
<create graph type statement> ::= 
  "CREATE" { "GRAPH TYPE" [ "IF NOT EXISTS" ] | "OR REPLACE GRAPH TYPE" } <graph type name>
  <inline graph type> | <cloned graph type> | <inferred graph type>

Inline Specification

Define the node and edge types directly in the CREATE GRAPH TYPE statement.

Syntax
<inline graph type> ::= "{" [ <element type> [ { "," <element type> }... ] ] "}"

<element type> = <node type> | <edge type>

Learn more about node types and edge types.

Create an empty graph type that schema can be added to later:

GQL
CREATE GRAPH TYPE socialType

Create a graph type with an inline specification:

GQL
CREATE GRAPH TYPE gType {
  NODE User ({name STRING, age UINT32}),
  NODE Club ({name STRING}),
  EDGE FOLLOWS ()-[{createdOn TIMESTAMP}]->(),
  EDGE JOINS ()-[]->()
}

Cloning a Graph Type

Syntax
<cloned graph type> ::= "AS COPY OF" <graph type name>

Create a graph type that is a copy of another graph type:

GQL
CREATE GRAPH TYPE socialType AS COPY OF gType

Inferring a Graph Type

Syntax
<inferred graph type> ::= "LIKE" <graph name>

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:

GQL
CREATE 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.

Using IF NOT EXISTS

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.

GQL
CREATE GRAPH TYPE IF NOT EXISTS socialType {
  NODE Person ({name STRING, email STRING})
}

Using OR REPLACE

You can use OR REPLACE to drop the existing graph type with the same name and create a new one in its place:

GQL
CREATE OR REPLACE GRAPH TYPE socialType {
  NODE Person ({name STRING, email STRING})
}

Adding Node/Edge Types

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)

Dropping Node/Edge Types

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

Renaming Graph Types

Rename socialType to communityType:

GQL
ALTER GRAPH TYPE socialType RENAME TO communityType

Commenting Graph Types

Set comment for communityType:

GQL
ALTER GRAPH TYPE communityType COMMENT 'Schema for social-network graphs'

Dropping Graph Types

Drop the graph type socialType:

GQL
DROP 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.

GQL
DROP GRAPH TYPE IF EXISTS socialType

Bounding to Graphs

Create a graph using a named graph type, see Closed Graphs. Once a graph is bound to a graph type, the binding semantics are strict:

  • The binding is immutable for the bound graph's lifetime. You can unbound it, but there is no rebind to switch types.
  • Any changes on a graph type propagates automatically to every bound graph. Altering a node or edge type on the named graph type immediately re-shapes the schema of every graph bound to it.
  • Direct schema evolution is rejected on a bound graph. Detach it first if you want this graph to diverge.
  • A graph type cannot be dropped while any graph is bound to it.