YetAnotherToDoList/graph/schema.graphqls

151 lines
3.2 KiB
GraphQL
Raw Normal View History

2023-08-19 23:47:36 +02:00
# YetAnotherToDoList
# Copyright © 2023 gilex-dev gilex-dev@proton.me
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# GraphQL schema example
#
# https://gqlgen.com/getting-started/
type Todo {
id: ID!
text: String!
done: Boolean!
user: User!
2023-08-19 23:47:36 +02:00
}
type User {
id: ID!
userName: String!
fullName: String
todos: [Todo!]!
roles: [RelationUserRole!]!
}
type RelationUserRole {
role: Role!
userIsRoleManager: Boolean!
}
type RelationRoleUser {
user: User!
userIsRoleManager: Boolean!
}
type Role {
id: ID!
roleName: String!
isAdmin: Boolean!
isUserCreator: Boolean!
roleMembers: [RelationRoleUser!]!
}
type RefreshToken {
id: ID!
expiryDate: Int!
tokenName: String
selector: String
token: String
userId: String!
2023-08-19 23:47:36 +02:00
}
type Query {
todos: [Todo!]! @hasPrivilege(privilege: isAdmin)
users: [User!]!
roles: [Role!]!
refreshTokens: [RefreshToken!]! @hasPrivilege(privilege: isAdmin)
user(id: ID!): User!
todo(id: ID!): Todo!
role(id: ID!): Role!
refreshToken(id: ID!): RefreshToken!
}
input NewUser {
userName: String!
fullName: String
password: String!
2023-08-19 23:47:36 +02:00
}
input NewTodo {
text: String!
userId: ID!
}
input NewRole {
roleName: String!
isAdmin: Boolean!
isUserCreator: Boolean!
}
input NewRefreshToken {
tokenName: String
}
input UpdateTodo {
text: String
done: Boolean
}
input UpdateUser {
userName: String
fullName: String
password: String
}
input UpdateRole {
roleName: String
isAdmin: Boolean
isUserCreator: Boolean
}
input UpdateRefreshToken {
tokenName: String
2023-08-19 23:47:36 +02:00
}
type Mutation {
createUser(input: NewUser!): User! @hasPrivilege(privilege: isUserCreator)
createTodo(input: NewTodo!): Todo!
createRole(input: NewRole!): Role! @hasPrivilege(privilege: isAdmin)
createRefreshToken(input: NewRefreshToken!): RefreshToken!
updateTodo(id: ID!, changes: UpdateTodo!): Todo!
updateUser(id: ID!, changes: UpdateUser!): User!
updateRole(id: ID!, changes: UpdateRole!): Role!
@hasPrivilege(privilege: isAdmin)
updateRefreshToken(id: ID!, changes: UpdateRefreshToken!): RefreshToken!
deleteUser(id: ID!): ID @hasPrivilege(privilege: isAdmin)
deleteTodo(id: ID!): ID
deleteRole(id: ID!): ID @hasPrivilege(privilege: isAdmin)
deleteRefreshToken(id: ID!): ID
addUserRole(
userId: ID!
roleId: ID!
userIsRoleManager: Boolean!
): [RelationUserRole!]! @hasPrivilege(privilege: isAdmin)
updateUserRole(
userId: ID!
roleId: ID!
userIsRoleManager: Boolean!
): [RelationUserRole!]! @hasPrivilege(privilege: isAdmin)
removeUserRole(userId: ID!, roleId: ID!): [RelationUserRole!]!
@hasPrivilege(privilege: isAdmin)
}
directive @hasPrivilege(privilege: Privilege!) on FIELD_DEFINITION
directive @asUser(id: ID!) on MUTATION | QUERY
enum Privilege {
isAdmin
isUserCreator
2023-08-19 23:47:36 +02:00
}