Skip to content

Add latest_released_at sort options to GraphQL ciCatalogResources

Leaminn Ma requested to merge add-gql-sort-released-cicatalogresources into master

What does this MR do and why?

In !132429 (merged), we added the latest_released_at column to catalog_resources.

This MR adds the option to sort by latest_released_at for the GraphQL ciCatalogResources endpoint.

Note that the column is always null for now. It will be updated via services described in Step 3 of #408382 (closed). You will have to manually update the column via the Rails console for testing purposes.

Resolves Step 2 of #408382 (closed).

How to set up and validate locally

  1. Created 3 catalog resources.
  2. In the Rails console, update one of the resources with today's date and another with yesterday's date. Leave the third resource with a NULL latest_released_at value.
resource1.update!(latest_released_at: Time.zone.now)
resource2.update!(latest_released_at: Time.zone.now - 1.day)
  1. In http://gdk.test:3000/-/graphql-explorer, test the following query:
query getCiCatalogResources {
  ciCatalogResources(sort: LATEST_RELEASED_AT_DESC, projectPath: "group-a/project-catalog-resource-1") {
    nodes {
      name
      latestReleasedAt
    }
  }
}
  1. Observe the output. It should show the resources ordered by latest_released_at descending with the NULL value last.

Screenshot_2023-09-27_at_11.43.32_AM

  1. Update the query with LATEST_RELEASED_AT_ASC and confirm the output is as expected.

Screenshot_2023-09-27_at_11.43.53_AM

  1. (Optional) You can also confirm that the pagination works as expected. Example:
query getCiCatalogResources {
  ciCatalogResources(after: null, first: 1, sort: LATEST_RELEASED_AT_DESC, projectPath: "group-a/project-catalog-resource-1") {
    nodes {
      name
      latestReleasedAt
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
  }
}

Query plans

SELECT "catalog_resources".* FROM "catalog_resources" ORDER BY "catalog_resources"."latest_released_at" DESC NULLS LAST

Looks good - Query plan link

SELECT "catalog_resources".* FROM "catalog_resources" ORDER BY "catalog_resources"."latest_released_at" ASC NULLS LAST

Looks good - Query plan link

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 #408382 (closed)

Edited by Leaminn Ma

Merge request reports