Hello everybody,
I’m new to Dgraph and GraphQL and so far everything was quite impressive in my first tests But now that I’m trying to create an advanced schema for my database, I encountered a problem. Maybe you can help me to wrap my head around this:
I want to create a very flexible way to store and connect data in the database (my approach is inspired by RDF). For that, I created 3 different types of base nodes: EntityNode, ValueNode, and ConnectionNode. The EntityNode is only an empty node that is used as a starting point for all connections to other entities and the connected values to this entity. A ValueNode stores only one piece of information. And between them, there is always a ConnectionNode, which connects them with a special type.
My problem is, that the ConnectionNOde should not only connect one EntityNode to one ValueNode but should connect two EntityNodes or two ValueNode as well. I thought “easy, I just use an Interface”, but I want to make the connections always two-edged for easy traversal, so I have a problem.
Here is my last approach, maybe someone can give me a hint on how I can update my schema so I can add @hasInverse to the Nodes.
# base entity node
interface EntityNode {
id: ID!
connections: [ConnectionNode] #hasInverse <- but what field should I name???
}
# base value node
interface ValueNode {
connections: [ConnectionNode] #hasInverse <- but what field should I name???
}
interface ConnectionNode {
connectionType: ConnectionType! @search
...
}
type EntityConnectionNode implements ConnectionNode {
node1: EntityNode!
node2: EntityNode!
}
type ValueConnectionNode implements ConnectionNode {
node1: ValueNode!
node2: ValueNode!
}
type EntityValConnectionNode implements ConnectionNode{
entityNode: EntityNode!
valueNode: ValueNode!
}
enum ConnectionType {
...
}
I hope my explanation of the problem was understandable, if not, pls. ask any questions