you can
roles as var(func: eq(name, "admin", "stuff"))
users(func: eq(_type, "user")) @cascade {
roles @filter(uid(roles))
uid
name
}
but it will work slow
- use different names for edges for users and roles, to not index and lookup all name values but only related to role.
- don’t use eq for filtering by type, because it uses index lookup. create edge with typeUser name instead and query using
has(typeUser)
function
- don’t get all users and then filter by role. it’s not sql, you should use graph way instead:
result(func: eq(roleName, "stuff", "admin")) {
~roles {
userName
uid
}
}
since you know that roles
edge is always connecting user and role, you can use reverse edge to retrieve user by role. you can save users in a var and use in another block.
var(func: eq(roleName, "stuff", "admin")) {
users as ~roles
}
users(func: uid(users)) {
uid
userName
}
if roles
edge in your schema is used not only for users, you should modify your schema or use @filter(has(typeUser))
on ~roles
edge (this option is worse)
result(func: eq(roleName, "stuff", "admin")) {
~roles @filter(has(typeUser)) {
userName
uid
}
}