Schema
A .pg file defines your graph's structure. The node types, edge types, interfaces, and constraints that the query engine enforces.
Every Omnigraph graph starts with a schema. The schema is a single .pg file that declares what kinds of entities and relationships exist in your graph, what properties they carry, and what rules apply to the data.
What a .pg file looks like
// Line comments use //, and /* block comments */ are also accepted.
node Person {
name: String @key
age: I32?
}
node Company {
name: String @key
}
edge Knows: Person -> Person {
since: Date?
}
edge WorksAt: Person -> CompanyType names must begin with an uppercase ASCII letter (Person, WorksAt).
Property names, parameter names, and other identifiers must begin with a
lowercase ASCII letter or _. Property declarations must be on separate
lines inside the body. Comma-separated single-line bodies are a parse
error.
The three declaration kinds
| Keyword | Purpose |
|---|---|
node | A vertex type with typed properties |
edge | A directed relationship between two node types |
interface | A named set of properties that node types can implement |
Every node and edge gets its own storage table. Interfaces are compile-time only.
What the schema drives
When Omnigraph opens a graph, it compiles the stored schema source into a catalog:
- Typecheck queries. Property references, traversal paths, and filter expressions are validated against the declared types.
- Create and validate storage. One data table is created per node type and per edge type.
- Enforce constraints,
@range,@check, and edge cardinality annotations are checked at load and mutation time. - Build indices,
@indexand@keyannotations cause BTree (scalar), inverted (full-text), orivf_flat(vector) indexes to be created.