Skip to content

Add GraphQL search filter and sort by created_at to ciCatalogResources

Leaminn Ma requested to merge add-gql-search-filter-catalog-resources into master

What does this MR do and why?

This MR:

  • Adds the search field to the GraphQL endpoint ciCatalogResources. The ability to query the resources by search term was already added in !134517 (diffs), so this MR just exposes the field for use.
  • Adds created_at sort options to the same endpoint.
  • Refactors spec/graphql/resolvers/ci/catalog/resources_resolver_spec.rb for clarity.

Resolves #429117 (closed).

How to set up and validate locally

  1. Under the same parent group, create 2 projects with README files named Orange Project and Apple Project. (These names just need to be unique. We simply want to set up a situation where only one or both of these projects are returned by the search filter.)
  2. Update the description of Orange Project to Foo; update the description of Apple Project to Orange.
  3. In the console, first mark Orange Project as a catalog resource, then mark Apple Project as a catalog resource.
Ci::Catalog::Resource.create!(project: Project.find_by(name: 'Orange Project'))
Ci::Catalog::Resource.create!(project: Project.find_by(name: 'Apple Project'))
  1. Go to http://gdk.test:3000/ and test the following query (update the group name as necessary):
query {
  ciCatalogResources(projectPath: "group-a/orange-project", search: "orange") {
    nodes {
      id
      name
    }
  }
}

Observe that both projects from Step 1 are in the response.

Screenshot_2023-10-23_at_12.36.46_PM

  1. If you change the search term to "apple", then only Apple Project will show.

Screenshot_2023-10-23_at_12.37.26_PM

  1. Now test the sorting with the following query:
query {
  ciCatalogResources(projectPath: "group-a/orange-project", search: "orange", sort: CREATED_ASC) {
    nodes {
      id
      name
    }
  }
}

Orange Project should appear first in the list.

Screenshot_2023-10-23_at_12.42.26_PM

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

Edited by Leaminn Ma

Merge request reports