Skip to content

Add sorting by key to GraphQL ciVariables field

Leaminn Ma requested to merge 387803-BE-sort-graphql-ci-variables into master

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

  1. 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.)
  2. Go to http://gdk.test:3000/-/graphql-explorer.
  3. Run the following queries as applicable to the level you're testing, and observe the output when sort is set to KEY_ASC, KEY_DESC, or not set at all null. You can also test that it works with the existing pagination infrastructure by changing the first and after 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"}
Example output with KEY_ASC Screenshot_2023-01-20_at_11.40.39_AM

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"}
Example output with KEY_ASC Screenshot_2023-01-20_at_11.45.38_AM

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"}
Example output with KEY_ASC Screenshot_2023-01-20_at_11.50.41_AM

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #387803 (closed)

Edited by Leaminn Ma

Merge request reports