graph
ontology.define_link_type
Define a graph link type.
strata graph ontology define-link-typedb.graphs.ontology.define_link_type(graph: 'str', name: 'str', source: 'str', target: 'str', *, cardinality: 'Optional[str]' = None, properties: 'Optional[dict]' = None) -> 'Any'wire graph_define_link_type
Declares a link type in the graph's ontology: a name, its source and target object types, an optional cardinality hint (for example `many-to-one`), and property definitions. Source and target must name declared object types by the time the ontology is frozen. After freezing, this command fails with `failed_precondition.engine.graph_ontology_frozen`.
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 ontology define-link-type --helphelp(db.graphs.ontology.define_link_type)
Example
Define a link (edge) type between two object types.
strata graph create gstrata graph ontology define-object-type g personstrata graph ontology define-link-type g knows person personstrata graph ontology get g
_ = db.graphs.create("g")_ = db.graphs.ontology.define_object_type("g", "person")_ = db.graphs.ontology.define_link_type("g", "knows", "person", "person")[l.name for l in db.graphs.ontology.get("g").link_types]
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| graph | string | yes | Graph name. |
| name | string | yes | Link type name. |
| source | string | yes | Declared source object type. |
| target | string | yes | Declared target object type. |
| branch | string or null | no | Target branch. Defaults to the executor handle branch. |
| cardinality | string or null | no | Optional cardinality: one of `one-to-one`, `one-to-many`, `many-to-one`, or `many-to-many`. Unknown values are rejected. |
| properties | object | no | Declared properties by name. |
| space | string or null | no | Target product space. Defaults to `"default"`. |
Returns
MutationAck<GraphOntologyWrite>
- 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_type_name | never | not_started |
| invalid_argument.engine.graph_type_name_reserved | never | not_started |
| invalid_argument.engine.graph_property_name | never | not_started |
| failed_precondition.engine.graph_ontology_frozen | never | not_started |