I have the following schema:
type User {
id: String! @id
name: String
}
type Group {
id: String! @id
owner: User
members: [Member] @hasInverse(field: group)
posts: [Post] @hasInverse(field: group)
}
type Member {
id: String! @id
user: User
group: Group
is_owner: Boolean
level: Int
last_publish_at: DateTime
last_query_date: DateTime
...
}
type Post {
id: String! @id
user: User
group: Group
likes: [User]
...
}
1,How should I create a link between User
and Group
based on Member
?
I want to add the groups field to User in order to query my groups, it’s very simple:
type User {
id: String! @id
name: String
groups: [Group] @hasInverse(field: owner)
}
But I want to know which groups I have joined, and now I am facing difficulties. The members
of the group
are established by Member
instead of User
.
I want to implement the following solution, but dgraph does not currently support:
type User {
id: String! @id
name: String
join_groups: [Group] @hasInverse(field: members)
}
Or nested:
type User {
id: String! @id
name: String
join_groups: [Group] @hasInverse(field: members.user)
}
2,Implement multiple links based on @hasInverse directive
I want to know which posts I have created and liked. I want to aggregate them in the posts field. I don’t want to store them separately.
So I am expecting the following solution:
type User {
id: String! @id
name: String
join_groups: [Group] @hasInverse(field: members)
posts: [Post] @hasInverse(field: [user,likes])
}
Realized through multiple links, but currently dgraph does not support.
I am looking forward to a good solution.
I don’t know if the schema I designed is reasonable, if you have better suggestions, please feel free to put forward them.
I can also custom DQL deep query to achieve the above features, but I think that query will be very slow.