# GRAPH TYPE — Schema Enforcement DDL Introduced 2026.02 (preview) · **GA 2026.06** · Enterprise Edition, Infinigraph Edition, all Aura tiers · Cypher 25 only. GRAPH TYPE consolidates what previously required dozens of individual `CREATE CONSTRAINT` / `CREATE INDEX` statements into a single declarative schema definition. It operates on an **open model**: validation applies only to defined elements; extra labels and properties on nodes/relationships are still allowed. Underlying constraints generated by GRAPH TYPE are visible via `SHOW CONSTRAINTS`. --- ## Lifecycle Commands | Command | Purpose | Required privileges | |---|---|---| | `ALTER CURRENT GRAPH TYPE SET { … }` | Replace/initialise the graph type (full redeclaration; overwrites existing constraints) | `CREATE CONSTRAINT`, `DROP CONSTRAINT`, `NAME MANAGEMENT` | | `ALTER CURRENT GRAPH TYPE ADD { … }` | Add entirely new element types/constraints; cannot modify existing ones | `CREATE CONSTRAINT`, `NAME MANAGEMENT` | | `ALTER CURRENT GRAPH TYPE ALTER { … }` | Modify existing node/relationship element types | `CREATE CONSTRAINT`, `DROP CONSTRAINT`, `NAME MANAGEMENT` | | `ALTER CURRENT GRAPH TYPE DROP { … }` | Drop element types and named constraints; data preserved | `DROP CONSTRAINT` | | `SHOW CURRENT GRAPH TYPE` | Display the full enforced schema as a string | — | | `SHOW CURRENT GRAPH TYPE AS GRAPH` | [2026.06] Return schema as virtual nodes/relationships | — | `ALTER CURRENT GRAPH TYPE SET { }` clears the whole graph type. --- ## Element Type Syntax ``` (:IdentifyingLabel => [:Implied1[&Implied2…]] [{ prop :: TYPE [NOT NULL] [IS UNIQUE|KEY], … }]) ([:SourceLabel])-[:IDENTIFYING_REL_TYPE => [{ prop :: TYPE [NOT NULL], … }]]->([:TargetLabel]) ``` - `=>` is mandatory in every element type definition, even with no implied labels: `(:City => {name :: STRING})` - `!` is shorthand for `NOT NULL`: `(:Person => {name :: STRING!})` - `ANY` type allowed only with `NOT NULL`: `{since :: ANY NOT NULL}` - Identifying labels/rel types must be unique within a graph type; a label cannot be both identifying and implied - Relationship endpoints are optional: `(:Resident)-[:LIVES_IN =>]->()`, `()-[:LIVES_IN => {since :: DATE}]->()` - Composite or `REQUIRE`-based constraints need a bound variable: `(p:Person => …) REQUIRE (p.name, p.ssn) IS KEY` --- ## Command Examples ### Define or replace the full schema ```cypher CYPHER 25 ALTER CURRENT GRAPH TYPE SET { (p:Person => :Resident { id :: INTEGER NOT NULL, name :: STRING NOT NULL, born :: INTEGER }) REQUIRE p.id IS KEY, (:Movie => { movieId :: STRING IS KEY, title :: STRING NOT NULL, released :: INTEGER }), // Label implication: every Crew node must also be a Person (:Crew => :Person), // Relationship element types with enforced source and target labels (:Person)-[:ACTED_IN => { roles :: LIST }]->(:Movie), (:Person)-[:DIRECTED =>]->(:Movie), (:Person)-[:KNOWS => { since :: DATE }]->(:Person), // Named constraint on a non-identifying label CONSTRAINT resident_city FOR (r:Resident) REQUIRE r.city IS :: STRING } ``` ### Add new elements ```cypher CYPHER 25 ALTER CURRENT GRAPH TYPE ADD { (:Producer => { name :: STRING IS UNIQUE }), (:Producer)-[:PRODUCED =>]->(:Movie) } ``` ### Alter existing elements ```cypher CYPHER 25 ALTER CURRENT GRAPH TYPE ALTER { (:Producer => :Person { name :: STRING NOT NULL, agency :: STRING }), (:Person)-[:KNOWS => { since :: ANY NOT NULL }]->(:Person) } ``` ### Drop elements ```cypher CYPHER 25 ALTER CURRENT GRAPH TYPE DROP { (:Producer => ), // identifying label + `=>` drops whole node element type ()-[:PRODUCED => ]->(), CONSTRAINT resident_city // key/uniqueness constraints drop by name only } ``` Drop rules: - Partial definitions rejected — supply either identifying label + `=>` or the full definition - Property existence/type constraints belonging to an element type cannot be dropped separately - Key and property uniqueness constraints survive element-type drops → drop by `CONSTRAINT name` (names from `SHOW CONSTRAINTS`) - Node element type referenced as source/target of a relationship element type → `22NCE: node element type in use`; drop or alter the relationship element type first ### Inspect current schema ```cypher CYPHER 25 SHOW CURRENT GRAPH TYPE ``` ```cypher // [2026.06] virtual graph form: nodes labelled :NodeElementType / :NodeLabel / :AnyLabel, // relationships :RELATIONSHIP_ELEMENT_TYPE / :RELATIONSHIP_TYPE / :IMPLIES CYPHER 25 SHOW CURRENT GRAPH TYPE AS GRAPH ``` --- ## Property Types | Type keyword | Notes | |---|---| | `STRING` | UTF-8 string | | `INTEGER` | 64-bit signed integer | | `FLOAT` | 64-bit float | | `BOOLEAN` | true / false | | `DATE` | Calendar date | | `ZONED DATETIME` | Datetime with timezone | | `LOCAL DATETIME` | Datetime without timezone | | `DURATION` | ISO 8601 duration | | `POINT` | Spatial point | | `LIST` | Homogeneous list (e.g. `LIST`) | Append `NOT NULL` to prohibit null values: `name :: STRING NOT NULL` --- ## Constraints Within GRAPH TYPE | Syntax | Equivalent standalone constraint | |---|---| | `REQUIRE node.prop IS KEY` | `CREATE CONSTRAINT … REQUIRE n.prop IS NODE KEY` | | `REQUIRE node.prop IS UNIQUE` | `CREATE CONSTRAINT … REQUIRE n.prop IS UNIQUE` | | `prop :: TYPE IS KEY` / `IS UNIQUE` (inline, single property) | same as above, no variable needed | | `prop :: TYPE NOT NULL` (inside node def) | `CREATE CONSTRAINT … REQUIRE n.prop IS NOT NULL` | | `CONSTRAINT name FOR (n:Label) REQUIRE …` (inside block) | named constraint; required for non-identifying labels | `SHOW CURRENT GRAPH TYPE` renders every uniqueness/key constraint in `CONSTRAINT … FOR … REQUIRE` form regardless of how it was declared. --- ## Label Implications ```cypher (:Crew => :Person) // every :Crew node must also have :Person label (:Admin => :Person&Staff) // multiple implied labels — `&`-separated ``` The implication is enforced on write — Neo4j rejects or auto-adds the implied label depending on configuration. --- ## Relationship Type Enforcement ```cypher (:Person)-[:KNOWS => { since :: DATE }]->(:Person) ``` Creating a `:KNOWS` relationship from `:Movie` to `:Person` is rejected. --- ## When to Use GRAPH TYPE vs Individual Constraints | Scenario | Recommendation | |---|---| | Greenfield project on 2026.06+, Enterprise/Aura | Use GRAPH TYPE — single source of truth for the schema | | Existing database with many constraints already | Migrate incrementally with `ALTER CURRENT GRAPH TYPE ADD` | | On 2026.02–2026.05 | Same syntax, preview status — validate on a scratch database first | | Neo4j < 2026.02 or Community Edition | Use `CREATE CONSTRAINT IF NOT EXISTS` per property | --- ## Fallback (pre-2026.02) ```cypher CREATE CONSTRAINT IF NOT EXISTS FOR (n:Person) REQUIRE n.id IS NODE KEY; CREATE CONSTRAINT IF NOT EXISTS FOR (n:Movie) REQUIRE n.movieId IS UNIQUE; CREATE CONSTRAINT IF NOT EXISTS FOR (n:Person) REQUIRE n.name IS NOT NULL; ``` --- ## References - Docs: `https://neo4j.com/docs/cypher-manual/current/schema/graph-types/` - Set / add / alter / drop / show sub-pages: `https://neo4j.com/docs/cypher-manual/current/schema/graph-types/{set-graph-types,extend-graph-types,alter-element-types,drop-graph-type-elements,list-graph-types}/`