User
Adds a query field to get the current user and additional fields on the User
type to check for permissions or roles.
Schema
Extension
graphql
extend type Query {
currentUser: User
}
extend type User {
hasPermission(permission: String!): Boolean!
}
extend type User {
"""
Check if the user has the given role.
"""
hasRole(role: String!): Boolean!
"""
Contains a list of all roles of this user.
"""
roleIds: [String]
}
Examples
Get current user
graphql
query {
currentUser {
id
hasPermission(permission: "access toolbar")
hasRole(role: "administrator")
roleIds
}
}
json
{
"data": {
"currentUser": {
"id": "1",
"hasPermission": true,
"hasRole": true,
"roleIds": ["authenticated", "administrator"]
}
}
}