Hi, I am beginning to explore graph database and I am learning how to use Dgraph database. I wanted to play around so I tried to build a schema as follows
Datacenter → Servers → IpAddress → IpAddressPorts → Service
Each Datacenter can have many Servers
Each Server can have many IpAddresses
Each IpAddress can have many Ports
Each Port has a Service
I came up with the following schema
<HasServers>: [uid] @reverse .
<HasIpAddresses>: [uid] @reverse .
<HasIpPortNumbers>: [uid] @reverse .
<HasService>: uid @reverse .
<IpAddress>: string @index(exact) .
<Name>: string @index(exact) .
<PortNumber>: int .
type <Datacenter> {
Name
HasServers
}
type <Server> {
Name
HasIpAddresses
}
type <IpAddress> {
IpAddress
HasIpPortNumbers
}
type <IpPortNumber> {
PortNumber
HasService
}
type <DgraphDatabaseService> {
Name
}
now to get the services of a Datacenter i can use this
servicesUnderDatacenter (func: type(Datacenter)){
uid
Name
HasServers{
uid
Name
HasIpAddresses{
uid
IpAddress
HasIpPortNumbers{
uid
PortNumber
HasService{
uid
Name
}
}
}
}
}
to get the Datacenter of a Service i can use this
datacenterOfService(func: type(DgraphDatabaseService)){
uid
Name
~HasService {
uid
PortNumber
~HasIpPortNumbers {
uid
IpAddress
~HasIpAddresses {
uid
Name
~HasServers {
uid
Name
}
}
}
}
}
So to go from Datacenter to service i got to traverse all the paths down and to get the Datacenter i traverse up.
The question is, is it the correct way to create the design of the relationships or should i include the “Datacenter” field in the “Service” Type so i have direct access to Datacenter?
Same to know the IpAddress and Port of the Service, should i include in the DgraphDatabaseService (type) the predicates UseIpAddress and UsePortNumber so i can get them more easily?
Am i making use of the “reverse” feature too much?
What is the best practice here?