graph
edge.add
Add or replace a graph edge.
strata graph add-edgedb.graphs.add_edge(graph: 'str', src: 'str', edge_type: 'str', dst: 'str', *, weight: 'Optional[float]' = None, properties: 'Optional[dict]' = None) -> 'Any'wire graph_add_edge
Adds a directed edge `src -[edge_type]-> dst` or replaces it if the same triple already exists. Both endpoints must already exist; writing an edge to a missing node fails with `invalid_argument.engine.graph_edge_endpoint`. Weight defaults to 1.0 and must not be negative. Once the graph's ontology is frozen, the edge type and its endpoint object types are validated against the declared link types.
Successful mutations return an acknowledgement of the outcome: for a state-changing write, the affected target with the mutation effect and commit facts; for mutations that produce a domain result (such as a branch or a promotion outcome), that result object.
To see the complete help for this command, run:
strata graph add-edge --helphelp(db.graphs.add_edge)
Example
Add a typed edge between two nodes.
strata graph create socialstrata graph add-node social alicestrata graph add-node social bobstrata graph add-edge social alice knows bobstrata graph get-edge social alice knows bob
_ = db.graphs.create("social")_ = db.graphs.add_node("social", "alice")_ = db.graphs.add_node("social", "bob")_ = db.graphs.add_edge("social", "alice", "knows", "bob")db.graphs.get_edge("social", "alice", "knows", "bob").edge_type
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| dst | string | yes | Destination node id. |
| edge_type | string | yes | Edge type. |
| graph | string | yes | Graph name. |
| src | string | yes | Source node id. |
| branch | string or null | no | Target branch. Defaults to the executor handle branch. |
| properties | any | no | Optional edge properties. |
| space | string or null | no | Target product space. Defaults to `"default"`. |
| weight | number or null | no | Optional edge weight. Defaults to 1.0. |
Returns
MutationAck<GraphEdgeWrite>
- dataobject
- typestring
Errors
Recover by code. Retry policy and commit outcome come from the shipped error registry.
| Code | Retry | Commit outcome |
|---|---|---|
| failed_precondition.engine.runtime_closed | never | not_started |
| not_found.engine.branch | never | not_applicable |
| invalid_argument.engine.product_space | never | not_started |
| invalid_argument.engine.graph_name | never | not_started |
| not_found.engine.graph | never | not_applicable |
| invalid_argument.engine.graph_node_id | never | not_started |
| invalid_argument.engine.graph_edge_type | never | not_started |
| invalid_argument.engine.graph_edge_type_reserved | never | not_started |
| invalid_argument.engine.graph_edge_weight | never | not_started |
| invalid_argument.engine.graph_edge_endpoint | never | not_started |
| invalid_argument.engine.graph_properties | never | not_started |
| invalid_argument.engine.graph_properties_too_large | never | not_started |
| failed_precondition.engine.graph_negative_weight | never | not_started |
| failed_precondition.engine.graph_ontology_edge_type | never | not_started |
| failed_precondition.engine.graph_ontology_endpoint_type | never | not_started |