Add GraphQL query for deployments (basics)
What does this MR do and why?
This MR adds GraphQL query for fetching deployment information. It adds the following changes:
- Add
DeploymentType
that can be fetched underEnvironmentType
. In this MR, it can only fetch basic data, such asid
andref
. - Add
DeploymentsResolver
to fetch deployments of environments. - Extend
DeploymentsFinder
to filter by multiple statuses, e.g.WHERE status IN (success, failed, canceled)
. - Extend
DeploymentsFinder
to filter by environment ID, e.g.WHERE environment_id = 123
. - Adjust
InefficientQueryError
guard to prevent inefficient parameter combinations.
A few notes:
- Following the official GraphQL documentation about the convention of sorting params. See more in the Slack discussion.
- It turned out that both GraphQL BatchLoader and GraphQL pagination can NOT be used in the same resolver together. In the
DeploymentsResolver
, we support pagination only. We'd consider adding a new single field (e.g.last_deployment
) for loading deployments from multiple environments, in order to support Environment Index page.
Query example
Get deployments of the environment
project(fullPath: "shinya.maeda/pipeline-playground") {
environment(name: "production") {
deployments {
nodes {
id
iid
ref
tag
sha
createdAt
updatedAt
finishedAt
status
}
}
}
}
Get the last deployment of the environment
project(fullPath: "shinya.maeda/pipeline-playground") {
environment(name: "production") {
deployments(statuses: [SUCCESS], orderBy: { finishedAt: DESC }, first: 1) {
nodes {
iid
}
}
}
}
Get the latest upcoming deployment of the environment
project(fullPath: "shinya.maeda/pipeline-playground") {
environment(name: "production") {
deployments(statuses: [CREATED RUNNING BLOCKED], orderBy: { createdAt: DESC }, first: 1) {
nodes {
iid
}
}
}
}
Related #368680 (closed)
Describe in detail what your merge request does and why.
Screenshots or screen recordings
sample query
{
project(fullPath: "root/pipeline-playground") {
environment(name: "prod") {
deployments {
nodes {
id
iid
ref
tag
sha
createdAt
updatedAt
finishedAt
status
}
}
}
}
}
sample response
{
"data": {
"project": {
"environment": {
"deployments": {
"nodes": [
{
"id": "gid://gitlab/Deployment/90",
"iid": "11",
"ref": "main",
"tag": false,
"sha": "4dce7b48d7c0250fd80ff5b132112c9af10b0c62",
"createdAt": "2022-07-28T05:39:23Z",
"updatedAt": "2022-07-29T07:00:51Z",
"finishedAt": "2022-07-29T07:00:07Z",
"status": "FAILED"
},
{
"id": "gid://gitlab/Deployment/89",
"iid": "10",
"ref": "feaw-tweatwe",
"tag": false,
"sha": "06ec69c77c71caf0a8594d972fc3e4579e5a0bb7",
"createdAt": "2022-07-08T06:37:33Z",
"updatedAt": "2022-07-08T06:37:57Z",
"finishedAt": "2022-07-08T06:37:57Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/88",
"iid": "9",
"ref": "fea-tgag",
"tag": false,
"sha": "1cd485021b332d5c2a15c52e39b3ae659c6ff69f",
"createdAt": "2022-07-07T10:07:55Z",
"updatedAt": "2022-07-07T10:08:00Z",
"finishedAt": "2022-07-07T10:08:00Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/87",
"iid": "8",
"ref": "main",
"tag": false,
"sha": "4dce7b48d7c0250fd80ff5b132112c9af10b0c62",
"createdAt": "2022-07-07T09:45:47Z",
"updatedAt": "2022-07-07T09:45:50Z",
"finishedAt": "2022-07-07T09:45:50Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/86",
"iid": "7",
"ref": "main",
"tag": false,
"sha": "31fc4de87a659e793ff58ec0fc5543e9a14a49cf",
"createdAt": "2022-07-07T09:35:37Z",
"updatedAt": "2022-07-07T09:35:41Z",
"finishedAt": "2022-07-07T09:35:41Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/85",
"iid": "6",
"ref": "main",
"tag": false,
"sha": "42481a0e3f2a74913e7882e8032fb5aa4f1000c7",
"createdAt": "2022-07-07T09:32:13Z",
"updatedAt": "2022-07-07T09:32:32Z",
"finishedAt": "2022-07-07T09:32:32Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/54",
"iid": "5",
"ref": "main",
"tag": false,
"sha": "0eb9c39a1b4ef86b46bcb7a1680039637d2ff619",
"createdAt": "2022-07-07T06:51:36Z",
"updatedAt": "2022-07-07T06:51:40Z",
"finishedAt": "2022-07-07T06:51:40Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/53",
"iid": "4",
"ref": "fe-asdfdasf",
"tag": false,
"sha": "c673e64ec1f05a68994063a16e8ced6ed8ecae8f",
"createdAt": "2022-07-07T06:50:23Z",
"updatedAt": "2022-07-07T06:50:28Z",
"finishedAt": "2022-07-07T06:50:28Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/52",
"iid": "3",
"ref": "fe-asdfdasf",
"tag": false,
"sha": "df3849416927bc5adaee0769f2f1d6bb7d573866",
"createdAt": "2022-07-07T06:49:05Z",
"updatedAt": "2022-07-07T06:49:07Z",
"finishedAt": "2022-07-07T06:49:07Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/51",
"iid": "2",
"ref": "main",
"tag": false,
"sha": "eb9974dab65530ef95310e7890230b8450c78d13",
"createdAt": "2022-07-07T06:46:13Z",
"updatedAt": "2022-07-07T06:46:16Z",
"finishedAt": "2022-07-07T06:46:16Z",
"status": "SUCCESS"
},
{
"id": "gid://gitlab/Deployment/50",
"iid": "1",
"ref": "main",
"tag": false,
"sha": "875b424809585e5f078dcec2032f74a83c78f960",
"createdAt": "2022-07-07T06:38:58Z",
"updatedAt": "2022-07-07T06:42:04Z",
"finishedAt": "2022-07-07T06:42:04Z",
"status": "SUCCESS"
}
]
}
}
}
}
}
Database query example with multiple statuses
SELECT "deployments".* FROM "deployments" WHERE "deployments"."environment_id" = 1178942 AND "deployments"."status" IN (2, 3, 4) ORDER BY "deployments"."id" ASC LIMIT 100
How to set up and validate locally
Access to GraphiQL and try execute the above queries.
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