Graphs
A graph is a definition over data you already have: which objects are its nodes and which relations or objects connect them as edges. Ownership structures, organisation charts and taxonomies are graphs. They span several classes and can contain cycles, such as two companies that hold shares in each other.
A graph describes data only: nodes, edges, how long an edge holds, and which values travel with them. It says nothing about how the graph is drawn. Showing a graph is the job of the GRAPH layout item, and the data is loaded through the Graph API. Your objects stay where they are; a graph is not separate storage.
Graph or view?
| View | Graph | |
|---|---|---|
| Shape | Flat rows of one class | Nodes and edges across several classes |
| Bounded by | Filters and paging | A scope (filter or object) or what is reachable from a center node |
| Typical display | Table, bar or pie chart | Orgchart |
| Loaded through | List and aggregations endpoints | /graphs/{tenant}/{graph} |
Use a view when you need a list or a simple chart of one class. Use a graph when the connections between objects are what the user wants to see.
Where to declare a graph
A graph spans classes, so it does not belong to any one of them. Declare graphs under graphDefinitions in a dedicated CONFIG class, conventionally in a file named graphs.json:
{
"version": 1,
"class": "entityhub.graphs",
"kind": "CONFIG",
"graphDefinitions": [
{ "graph": "entityhub.governance", "nodes": [...], "edges": [...] }
]
}
Add the file to index.json like any other class file. A CONFIG class has no objects of its own; see Class types.
Definition
| Property | Type | Description |
|---|---|---|
graph | QualifiedName | The graph's id, e.g. entityhub.governance. Namespace-governed like a class id; the system namespace is reserved. |
nodes | GraphNode[] | Per node class, which values to show of a node. Optional. |
edges | GraphEdge[] | The kinds of edge that connect nodes. At least one. |
description | string | Optional English description of what the graph shows. See Descriptions. |
The API names a graph by its REST name: the name part of the id, so entityhub.governance is served at /graphs/{tenant}/governance. Two graphs in one model cannot share a REST name, even in different namespaces.
Nodes
Which objects are nodes follows from the edges: every object at either end of an edge is a node. A nodes entry only adds what to show of a node of that class:
"nodes": [
{ "class": "commons.entity", "view": "graphNode" }
]
| Property | Type | Description |
|---|---|---|
class | QualifiedName | The node class. Applies to every node that has this class, also through a subclass or a role. |
view | string | A named view on that class (declared on it or inherited). The view's columns become the node's attributes. |
The view is an ordinary named view, so you can reuse it elsewhere or keep it just for the graph:
{
"version": 1,
"class": "commons.entity",
"views": [
{
"name": "graphNode",
"values": [
{ "name": "country" },
{ "name": "legalForm" }
]
}
]
}
A node without a matching nodes entry still appears in the graph, with its name but without attributes.
Edge kinds
Every entry in edges is an edge kind. One graph can mix kinds, for example shareholdings and directorships in one governance graph. Each kind has:
| Property | Type | Description |
|---|---|---|
edge | string | Name of the kind, lowerCamelCase and unique within the graph. Used by the API (?edges=) and the GRAPH item to select kinds. |
description | string | Optional English description of what this kind of edge means. See Descriptions. |
labelKey | string | The kind's display name as a label key, e.g. LABEL:shareholding. Translated like other labels. Required. |
An edge kind takes one of two forms.
Edge class
Every object of an edge class is one edge. Use this form when the connection has values of its own: a percentage, a start date, a position.
{
"edge": "shareholding",
"labelKey": "LABEL:shareholding",
"class": "entityhub.shareholding",
"from": "entityhub.shareholder",
"to": "commons.company",
"validFrom": "activeDate",
"validUntil": "inactiveDate",
"attributes": ["financialInterest", "votingInterest"]
}
| Property | Type | Description |
|---|---|---|
class | QualifiedName | The edge class. Each of its objects is one edge. |
from | QualifiedName | The class the edge starts at: the target of the edge class's relation to the start node. Must be a single relation. |
to | QualifiedName | The class the edge ends at: the target of the edge class's relation to the end node. Must be a single relation. |
validFrom | string | Optional. A DATE or DATETIME field of the edge class from which the edge holds. Empty means "since always". |
validUntil | string | Optional. A DATE or DATETIME field until which the edge holds. Empty means "still holds". |
label | string | Optional. A field whose value labels each individual edge, e.g. a director's position. Useful when one edge class holds several roles. |
attributes | string[] | Optional. Fields of the edge class sent along with each edge. |
Relations are named by their target class, as everywhere in a definition. So "from": "entityhub.shareholder" means: start the edge at the object that the shareholding's entityhub.shareholder relation points at.
Note the two label properties: labelKey names the kind ("Shareholding"), label names a field whose value labels each edge ("Statutory director", "Supervisory board member").
Relation as edge
A relation can be an edge by itself. Every object of from is connected to the object(s) its relation to relation points at. Use this form for plain hierarchies and memberships.
{ "edge": "membership", "labelKey": "LABEL:membership", "relation": "hr.department", "from": "hr.employee" }
| Property | Type | Description |
|---|---|---|
relation | QualifiedName | The target class of the relation that is the edge. |
from | QualifiedName | The class that declares the relation. Each of its objects is the start of an edge. |
The edge runs from the from object to the related object: employee → department, sub-department → parent department. There is no edge object, so the edge has no values of its own: class, to, validFrom, validUntil, label and attributes do not apply to this form.
Examples
Ownership and management of a group of companies
Shareholders hold shares in companies; persons are directors of companies. Both are edge classes with a validity period, so the graph also shows the structure as it was on an earlier date.
{
"version": 1,
"class": "entityhub.graphs",
"kind": "CONFIG",
"graphDefinitions": [
{
"graph": "entityhub.governance",
"nodes": [
{ "class": "commons.entity", "view": "graphNode" }
],
"edges": [
{
"edge": "shareholding",
"labelKey": "LABEL:shareholding",
"class": "entityhub.shareholding",
"from": "entityhub.shareholder",
"to": "commons.company",
"validFrom": "activeDate",
"validUntil": "inactiveDate",
"attributes": ["financialInterest", "votingInterest"]
},
{
"edge": "directorship",
"labelKey": "LABEL:directorship",
"class": "entityhub.directorship",
"from": "commons.person",
"to": "commons.company",
"validFrom": "startDate",
"validUntil": "endDate",
"label": "position",
"attributes": ["position", "authority"]
}
]
}
],
"translations": [
{
"language": "en",
"generalLabels": {
"shareholding": "Shareholding",
"directorship": "Directorship"
}
}
]
}
With this data:
entityhub.shareholding | shareholder | company | financialInterest | activeDate |
|---|---|---|---|---|
| 1 | Acme Holding B.V. | Acme Nederland B.V. | 1.0 | 2019-01-01 |
| 2 | Acme Holding B.V. | Acme Belgium NV | 0.6 | 2021-03-15 |
entityhub.directorship | person | company | position |
|---|---|---|---|
| 3 | Jane Smith | Acme Holding B.V. | Statutory director |
the graph has four nodes (Acme Holding, Acme Nederland, Acme Belgium, Jane Smith) and three edges: two of kind shareholding and one of kind directorship, labelled "Statutory director".
Departments and employees
An organisation chart needs no edge class: the relations already describe it. A department's relation to hr.department is its parent; an employee's relation to hr.department is where they work.
{
"graph": "hr.organisation",
"nodes": [
{ "class": "hr.department", "view": "graphNode" },
{ "class": "hr.employee", "view": "graphNode" }
],
"edges": [
{ "edge": "subDepartment", "labelKey": "LABEL:subDepartment", "relation": "hr.department", "from": "hr.department" },
{ "edge": "membership", "labelKey": "LABEL:membership", "relation": "hr.department", "from": "hr.employee" }
]
}
Validation
The model is checked when it loads; problems are reported as model issues (see Admin API). A graph is refused when:
- a class, view, relation or field it names does not exist;
- an edge class's relation to
fromortois a multiple relation; validFromorvalidUntilis not aDATEorDATETIMEfield;- an edge sets a property that does not apply to its form (e.g.
attributeson a relation edge); - an edge has no
labelKey, or itsedgename is missing, not lowerCamelCase, or used twice in the graph; - the graph has no edges;
- the graph id is declared twice, or two graphs share a REST name.
graphDefinitions is an additive property: adding it does not change the format version.