My question is about designing a GraphQL API.
We have 2 use-cases to get Users from the API:
- Get a list of all active users for things like mentions and assigning them to tasks. Here only the id, name and avatar of the user are required
- Managing users (active and inactive)
managing users should only be available for administrators, as well as the detailed properties of those users.
How would you implement that using best practices in graphql?
At the moment we are using a UserDTO for the public active users and a User type for the management users. We are thinking of consolidating them into a single user type but unsure whether that's the best approach.
(The API is implemented using .NET and HotChocolate)
This is our current implementation:
type UserDto {
id: String!
displayName: String!
avatar: String
}
type User {
id: String
isActive: Boolean!
userName: String!
email: String!
roles: [Role!]!
...
}
type Query {
users: [UserDto!]!
userList(skip: Int, take: Int): UserListCollectionSegment
}
type UserListCollectionSegment {
pageInfo: CollectionSegmentInfo!
items: [User!]
totalCount: Int!
}