visit
What is the ideal "quantum of information" or "minimal unit of meaning" and why ask such a question? There is a lot of pain associated with this, often not even realized. We offer a solution, but first, you need to figure out what it is for. We recommend you to read the first article in a series.
The link structure consists of the required unique id
and type_id
used as the type of this link. The optional from_id
and to_id
fields can only be specified together.
The specified from_id
and to_id
fields refer to other links. Any relationship can be described with such links.
{
links(where: { id: { _eq: 8 } }) {
id
type_id
from_id
to_id
}
}
{
"data": {
"links": [
{
"id": 8,
"type_id": 1,
"from_id": 7,
"to_id": 6
}
]
}
}
You can leave from_id
and to_id
fields empty in links. Such links play the role of a node, a point, an object of relations.
{
links(where: { id: { _eq: 28 } }) {
id
type_id
from_id
to_id
}
}
{
"data": {
"links": [
{
"id": 28,
"type_id": 6,
"from_id": 0,
"to_id": 0
}
]
}
}
If from_id
and to_id
are specified, the link plays the role of a relationship between nodes or links. It can answer the question of how they are related using type_id
. The environment of a node with links can answer many questions about its meaning, relationships, purpose, value, and state.
{
links(where: { id: { _in: [6,7,8] } }) {
id
type_id
from_id
to_id
}
}
{
"data": {
"links": [
{
"id": 6,
"type_id": 1,
"from_id": 0,
"to_id": 0
},
{
"id": 7,
"type_id": 1,
"from_id": 0,
"to_id": 0
},
{
"id": 8,
"type_id": 1,
"from_id": 7,
"to_id": 6
}
]
}
}
This API allows to do a lot of things, such as traversal to all children/parents in certain subtrees using index. But there will be separate articles about this.
Obviously, the structure of the link itself is available there, and also from a link, you can go to other links both by its links (from_id
and to_id
) and by backward references from other links (outgoing and incoming). For example, you can go to all links that refer to this link by from_id
(these links go from it) using relationship out
, or by to_id
(These links go to it) using relationship in
.
{
links(where: { id: { _eq: 8 } }) {
id
type { id }
from {
id
type_id
from_id
to_id
out {
id
type_id
from_id
to_id
}
}
to {
id
type_id
from_id
to_id
in {
id
type_id
from_id
to_id
}
}
}
}
{
"data": {
"links": [
{
"id": 8,
"type": {
"id": 1
},
"from": {
"id": 7,
"type_id": 1,
"from_id": 0,
"to_id": 0,
"out": [
{
"id": 8,
"type_id": 1,
"from_id": 7,
"to_id": 6
}
]
},
"to": {
"id": 6,
"type_id": 1,
"from_id": 0,
"to_id": 0,
"in": [
{
"id": 8,
"type_id": 1,
"from_id": 7,
"to_id": 6
},
{
"id": 13,
"type_id": 1,
"from_id": 6,
"to_id": 6
},
{
"id": 24,
"type_id": 22,
"from_id": 23,
"to_id": 6
}
]
}
}
]
}
}
We can receive not only the data on the structures described above. We can use the SQL-like where
predicate to perform a variety of complex filtering at each level.
{
links(where: {id: { _eq: 6 } }) {
id
type { id }
from { id }
to { id }
out(where: { from_id: { _eq: 6} }) {
id
type_id
from_id
to_id
}
in(where: { type_id: { _eq: 1} }, limit: 1) {
id
type_id
from_id
to_id
}
}
}
{
"data": {
"links": [
{
"id": 6,
"type": {
"id": 1
},
"from": null,
"to": null,
"out": [
{
"id": 13,
"type_id": 1,
"from_id": 6,
"to_id": 6
}
],
"in": [
{
"id": 8,
"type_id": 1,
"from_id": 7,
"to_id": 6
}
]
}
]
}
}
subscription {
links(where: { from_id: { _eq: 7 }, to_id: { _eq: 6 } }) {
id
type_id
}
}