Add sorting by key to GraphQL ciVariables field
What does this MR do and why?
This MR adds support for a sort
argument on the GraphQL ciVariables
field. This enables the variables to be sorted by key alphabetically at the Instance, Group, and Project levels.
The sort
options are KEY_ASC
or KEY_DESC
.
How to set up and validate locally
Follow the steps below for testing at all 3 levels: Instance, Group, and Project
- Go to Settings > CI/CD > Variables. Add a few variables with different key names (it's recommended to add them out of alphabetical order so that you can see the sort option in effect; the default behaviour lists them by ID descending.)
- Go to
http://gdk.test:3000/-/graphql-explorer
. - Run the following queries as applicable to the level you're testing, and observe the output when
sort
is set toKEY_ASC
,KEY_DESC
, or not set at allnull
. You can also test that it works with the existing pagination infrastructure by changing thefirst
andafter
variables accordingly.
Instance Query:
query getVariables($after: String, $first: Int = 2, $sort: CiVariableSort) {
ciVariables(after: $after, first: $first, sort: $sort) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
__typename
}
nodes {
id
key
__typename
}
__typename
}
}
Query Variables:
{"sort": "KEY_ASC"}
Group Query:
query getGroupVariables($after: String, $first: Int = 2, $fullPath: ID!, $sort: CiVariableSort) {
group(fullPath: $fullPath) {
id
ciVariables(after: $after, first: $first, sort: $sort) {
limit
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
__typename
}
nodes {
id
key
__typename
}
__typename
}
__typename
}
}
Query Variables:
{"fullPath": "group-a", "sort": "KEY_ASC"}
Project Query:
query getProjectVariables($after: String, $first: Int = 2, $fullPath: ID!, $sort: CiVariableSort) {
project(fullPath: $fullPath) {
id
ciVariables(after: $after, first: $first, sort: $sort) {
limit
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
__typename
}
nodes {
id
key
__typename
}
__typename
}
__typename
}
}
Query Variables:
{"fullPath": "group-a/project-6", "sort": "KEY_ASC"}
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.
Related to #387803 (closed)
Edited by Leaminn Ma