GraphQL query to get all projects and groups a user has access to
This is a follow up issue from #20532 (closed)
Problem to solve
We will introduce new REST endpoints with !22518 (merged) to get all projects and groups a user has access to. We would like the GraphQL API to be able to do the same. In #20532 (closed) it was also requested to have a way to limit down the fields returned by the API. With GraphQL, users can define which fields should be returned.
Further details
Our vision for GraphQL is that it should be the primary API. To archive this it is important that it offers at least the same features as the REST API.
Proposal
UserType should have a memberships field that returns all project and group membership of a user.
Example query to get all memberships for the logged in user:
Query:
{
currentUser{
memberships {
nodes {
sourceType
source_id
access_level
}
}
}
}
Response:
{
"data": {
"currentUser": {
"memberships": {
"nodes": [
{
"sourceType": "Project",
"sourceId": 35,
"accessLevel": "50"
},
{
"sourceType": "Group",
"sourceId": 3,
"accessLevel": "30"
}
]
}
}
}
}
Example query to get all ids of projects a user has access to:
Query:
{
user(id: 50){
memberships(sourceType: "Project") {
nodes {
source_id
}
}
}
}
Response:
{
"data": {
"user": {
"memberships": {
"nodes": [
{
"sourceId": 35,
},
{
"sourceId": 3,
}
]
}
}
}
}