GraphQL query for last deployment of environments
What does this MR do and why?
This MR extends GraphQL query for fetching last deployments of multiple environments. This is important functionality to render Environment Index page that horizontally display the information. Specifically, the following changes are included:
- We add a new field
lastDeployment
underenvironments
. - Query can receive
status
as an argument to get a specific status's last deployment, e.g. last success deployment, last failed deployment. - Backend loads the deployments in batch with
DeploymentPreloader
. - Since the sorting order for last deployments are different per finished vs upcoming context, so we specify a different ordering
ordered
vsordered_as_upcoming
. i.e. Last success deployment is the last deployment that finished at last, OTOH last running deployment is the last deployment that created at last. See !83558 (merged) for more context.
Related #370699 (closed)
Query example
{
project(fullPath: "dosuken-org/deployment-approval-test") {
environments {
nodes {
name
lastSuccessful: lastDeployment(status: SUCCESS) {
id
job {
name
}
}
lastRunning: lastDeployment(status: RUNNING) {
id
job {
name
}
}
lastBlocked: lastDeployment(status: BLOCKED) {
id
job {
name
}
}
}
}
}
}
Response
{
"data": {
"project": {
"environments": {
"nodes": [
{
"name": "staging",
"lastSuccessful": null,
"lastRunning": null,
"lastBlocked": null
},
{
"name": "production",
"lastSuccessful": {
"id": "gid://gitlab/Deployment/128",
"job": {
"name": "deploy"
}
},
"lastRunning": null,
"lastBlocked": {
"id": "gid://gitlab/Deployment/130",
"job": {
"name": "deploy"
}
}
}
]
}
}
}
}
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Shinya Maeda