I have this usecase that I need to output some user data, and if the user is admin then additional data should be outputted.
So how should I implement this: Can I do multiquery in DGraph? take output from query 1 and use it in query 2 in a single call?
Alternative which I have found is to first make a call, and check if user is admin, then do something like this: allowedPhones @include(if: $isAdmin) in 2. call.
But would be great if I can do all this in a single call.
type User {
id: ID!
authId: String! @search(by:[exact])
phone: String! @search(by:[exact,fulltext])
email: String @search(by:[exact,fulltext])
firstName: String! @search(by:[exact,fulltext])
lastName: String! @search(by:[exact,fulltext])
created: DateTime!
tags: [String] @search(by:[exact])
companies: [UserRole] @hasInverse(field:user)
...
}
type UserRole {
id: ID!
user: User!
company: Company!
role: Role! @search(by:[exact])
created: DateTime!
}
enum Role {
ADMIN
MANAGER
USER
GUEST
}
type Company {
id: ID!
...
users: [UserRole] @hasInverse(field:company)
allowedPhones: [String] @search(by:[exact])
}
Thanks for your reply, I’m not using auth in dgraph, it got complicated very quickly (Users can have different roles, on different companies.). And I’m not even sure I can implement the rules they way I want them. I’ll see if I can get pass this in my backend somehow.
Instead of Role being an enum, think about making it a type with each role then being it’s own node. (This may have pros/cons to your situation that you should weigh personally)
But I would still need to figure out their role, so by making this change I can then just query all roles/types and inside user role/type, just not ask for the data that I dont want to show hmm
query {
queryUser {
id
authId
phone
email
firstName
lastName
created
tags {
id
name
}
userRoles {
id
roles {
... on AdminRole {
id
company {
id
name
phone
email
tags {
id
name
}
created
start
end
allowedPhones {
id
phone
}
}
}
... on UserRole {
id
company {
id
name
phone
email
tags {
id
name
}
created
start
end
}
}
}
created
}
}
}
query MyQuery {
queryUser {
role {
userRole {
... on UserRoleAdmin {
id
company {
allowedPhones
email
id
}
}
... on UserRoleUser {
id
company {
email
id
}
}
}
}
}
}