Node & Edge Types
Overview
Section titled “Overview”The schema layer turns declarative type definitions into:
- Validated REST endpoints (via schema-to-api service)
- Zod schemas used for request body validation
- D1 metadata records that describe the graph’s shape
Node types
Section titled “Node types”A node type defines the shape of a node in the graph:
// Example node type definitionconst personType = { name: "Person", properties: { name: { type: "string", required: true }, age: { type: "number", required: false }, email: { type: "string", required: false }, },};Register it via the API:
POST /graphs/{graphId}/schema/node-types{ "name": "Person", "properties": { "name": { "type": "string", "required": true }, "age": { "type": "number", "required": false } }}Once registered, the following endpoints are automatically available:
| Method | Path | Action |
|---|---|---|
POST | /graphs/{id}/nodes/Person | Create a Person node |
GET | /graphs/{id}/nodes/Person/{nodeId} | Get a Person node |
PATCH | /graphs/{id}/nodes/Person/{nodeId} | Update a Person node |
DELETE | /graphs/{id}/nodes/Person/{nodeId} | Delete a Person node |
GET | /graphs/{id}/nodes/Person | List Person nodes |
Edge types
Section titled “Edge types”An edge type defines a directed relationship between two node types:
POST /graphs/{graphId}/schema/edge-types{ "name": "KNOWS", "sourceType": "Person", "targetType": "Person", "properties": { "since": { "type": "string", "required": false } }}Auto-generated edge endpoints:
| Method | Path |
|---|---|
POST | /graphs/{id}/edges/KNOWS |
GET | /graphs/{id}/edges/KNOWS/{edgeId} |
DELETE | /graphs/{id}/edges/KNOWS/{edgeId} |
GET | /graphs/{id}/edges/KNOWS |
Supported property types
Section titled “Supported property types”| Type | JSON representation |
|---|---|
string | "hello" |
number | 42, 3.14 |
boolean | true, false |
string[] | ["a", "b"] |
Validation
Section titled “Validation”All create and update requests are validated against the type’s Zod schema.
A request with an extra or missing required property returns:
{ "error": "Validation failed", "details": [{ "path": ["name"], "message": "Required" }]}