diff --git a/app/assets/javascripts/ci/runner/components/runner_projects.vue b/app/assets/javascripts/ci/runner/components/runner_projects.vue index 4cfc57340f5d6725026db628244077988d07bc98..ee67196e8e2d68898dc6eefea79c384e9aae54ef 100644 --- a/app/assets/javascripts/ci/runner/components/runner_projects.vue +++ b/app/assets/javascripts/ci/runner/components/runner_projects.vue @@ -71,6 +71,7 @@ export default { return { id: runner.id, search: search.length >= SHORT_SEARCH_LENGTH ? search : '', + sort: 'ID_ASC', ...getPaginationVariables(this.pagination, RUNNER_DETAILS_PROJECTS_PAGE_SIZE), }; }, diff --git a/app/assets/javascripts/ci/runner/graphql/show/runner_projects.query.graphql b/app/assets/javascripts/ci/runner/graphql/show/runner_projects.query.graphql index e42648b30795f556696f5019c0a24905c4c40433..589a549c52e5293c3efd9b4801c24eeef9eda0ef 100644 --- a/app/assets/javascripts/ci/runner/graphql/show/runner_projects.query.graphql +++ b/app/assets/javascripts/ci/runner/graphql/show/runner_projects.query.graphql @@ -3,6 +3,7 @@ query getRunnerProjects( $id: CiRunnerID! $search: String + $sort: String $first: Int $last: Int $before: String @@ -14,7 +15,14 @@ query getRunnerProjects( id } projectCount - projects(search: $search, first: $first, last: $last, before: $before, after: $after) { + projects( + search: $search + sort: $sort + first: $first + last: $last + before: $before + after: $after + ) { nodes { id avatarUrl diff --git a/app/graphql/resolvers/ci/runner_projects_resolver.rb b/app/graphql/resolvers/ci/runner_projects_resolver.rb index 99c9bba1bd674c2d58e3cbdceb7ca0183eac11d8..12fd2d7d0f2682b9b13a729803f548d78556198e 100644 --- a/app/graphql/resolvers/ci/runner_projects_resolver.rb +++ b/app/graphql/resolvers/ci/runner_projects_resolver.rb @@ -13,17 +13,6 @@ class RunnerProjectsResolver < BaseResolver alias_method :runner, :object - argument :sort, GraphQL::Types::String, - required: false, - default_value: 'id_asc', # TODO: Remove in %17.0 and move :sort to ProjectSearchArguments, see https://gitlab.com/gitlab-org/gitlab/-/issues/372117 - deprecated: { - reason: 'Default sort order will change in GitLab 17.0. ' \ - 'Specify `"id_asc"` if you require the query results to be ordered by ascending IDs', - milestone: '15.4' - }, - description: "Sort order of results. Format: `<field_name>_<sort_direction>`, " \ - "for example: `id_desc` or `name_asc`" - def resolve_with_lookahead(**args) return unless runner.project_type? diff --git a/app/graphql/resolvers/concerns/project_search_arguments.rb b/app/graphql/resolvers/concerns/project_search_arguments.rb index 560b75baa36a3b1dae715e2463adf56f8c9f7372..c59619bd1bed95c45968c6a5b302ceaba236ae6a 100644 --- a/app/graphql/resolvers/concerns/project_search_arguments.rb +++ b/app/graphql/resolvers/concerns/project_search_arguments.rb @@ -23,6 +23,12 @@ module ProjectSearchArguments argument :personal, GraphQL::Types::Boolean, required: false, description: 'Return only personal projects.' + + argument :sort, GraphQL::Types::String, + required: false, + default_value: 'id_desc', + description: "Sort order of results. Format: `<field_name>_<sort_direction>`, " \ + "for example: `id_desc` or `name_asc`" end private diff --git a/app/graphql/resolvers/projects_resolver.rb b/app/graphql/resolvers/projects_resolver.rb index 450caa9aff68c09501e9ace04e93008b72f58d71..336c16b0455bd7bfb59718fe68c94af112fcf963 100644 --- a/app/graphql/resolvers/projects_resolver.rb +++ b/app/graphql/resolvers/projects_resolver.rb @@ -15,11 +15,6 @@ class ProjectsResolver < BaseResolver required: false, description: 'Filter projects by full paths. You cannot provide more than 50 full paths.' - argument :sort, GraphQL::Types::String, - required: false, - description: "Sort order of results. Format: `<field_name>_<sort_direction>`, " \ - "for example: `id_desc` or `name_asc`" - argument :with_issues_enabled, GraphQL::Types::Boolean, required: false, description: "Return only projects with issues enabled." diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index c418eea251e5b000d24c3dc86eb696b77534456f..063fb164c5b38a4c2d4f05902a07c2bbc8e636d7 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -17373,7 +17373,7 @@ four standard [pagination arguments](#pagination-arguments): | <a id="cirunnerprojectspersonal"></a>`personal` | [`Boolean`](#boolean) | Return only personal projects. | | <a id="cirunnerprojectssearch"></a>`search` | [`String`](#string) | Search query, which can be for the project name, a path, or a description. | | <a id="cirunnerprojectssearchnamespaces"></a>`searchNamespaces` | [`Boolean`](#boolean) | Include namespace in project search. | -| <a id="cirunnerprojectssort"></a>`sort` **{warning-solid}** | [`String`](#string) | **Deprecated** in GitLab 15.4. Default sort order will change in GitLab 17.0. Specify `"id_asc"` if you require the query results to be ordered by ascending IDs. | +| <a id="cirunnerprojectssort"></a>`sort` | [`String`](#string) | Sort order of results. Format: `<field_name>_<sort_direction>`, for example: `id_desc` or `name_asc`. | | <a id="cirunnerprojectstopics"></a>`topics` | [`[String!]`](#string) | Filter projects by topics. | ##### `CiRunner.status` diff --git a/spec/frontend/ci/runner/components/runner_projects_spec.js b/spec/frontend/ci/runner/components/runner_projects_spec.js index 736a1f7d3ce8e58773e83d525a1fa35ef41e38aa..2cf9e577d7b6332b837ebe081020e6ce533fa051 100644 --- a/spec/frontend/ci/runner/components/runner_projects_spec.js +++ b/spec/frontend/ci/runner/components/runner_projects_spec.js @@ -67,6 +67,7 @@ describe('RunnerProjects', () => { expect(mockRunnerProjectsQuery).toHaveBeenCalledWith({ id: mockRunner.id, search: '', + sort: 'ID_ASC', first: RUNNER_DETAILS_PROJECTS_PAGE_SIZE, }); }); @@ -108,7 +109,6 @@ describe('RunnerProjects', () => { name, fullName: nameWithNamespace, avatarUrl, - isOwner: true, // first project is always owner }); }); @@ -124,6 +124,7 @@ describe('RunnerProjects', () => { expect(mockRunnerProjectsQuery).toHaveBeenLastCalledWith({ id: mockRunner.id, search: '', + sort: 'ID_ASC', first: RUNNER_DETAILS_PROJECTS_PAGE_SIZE, after: 'AFTER_CURSOR', }); @@ -138,6 +139,7 @@ describe('RunnerProjects', () => { expect(mockRunnerProjectsQuery).toHaveBeenLastCalledWith({ id: mockRunner.id, search: '', + sort: 'ID_ASC', last: RUNNER_DETAILS_PROJECTS_PAGE_SIZE, before: 'BEFORE_CURSOR', }); @@ -151,6 +153,7 @@ describe('RunnerProjects', () => { expect(mockRunnerProjectsQuery).toHaveBeenLastCalledWith({ id: mockRunner.id, search: 'my search', + sort: 'ID_ASC', first: RUNNER_DETAILS_PROJECTS_PAGE_SIZE, }); }); @@ -167,6 +170,7 @@ describe('RunnerProjects', () => { expect(mockRunnerProjectsQuery).toHaveBeenLastCalledWith({ id: mockRunner.id, search: 'my search', + sort: 'ID_ASC', first: RUNNER_DETAILS_PROJECTS_PAGE_SIZE, }); }); diff --git a/spec/graphql/resolvers/ci/runner_projects_resolver_spec.rb b/spec/graphql/resolvers/ci/runner_projects_resolver_spec.rb index c75d7fb831c8285a591e2917b42e81fd5870d231..05f26d141d5dee3e836ac07cae3c56f9aec7716c 100644 --- a/spec/graphql/resolvers/ci/runner_projects_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/runner_projects_resolver_spec.rb @@ -16,7 +16,7 @@ describe '#resolve' do context 'with authorized user', :enable_admin_mode do - let(:current_user) { create(:user, :admin) } + let_it_be(:current_user) { create(:user, :admin) } context 'with search argument' do let(:args) { { search: 'Project1.' } } @@ -69,15 +69,15 @@ end context 'without arguments' do - it 'returns a lazy value with all projects sorted by :id_asc' do + it 'returns a lazy value with all projects sorted by :id_desc' do expect(subject).to be_a(GraphQL::Execution::Lazy) - expect(subject.value.items).to eq([project1, project2, project3]) + expect(subject.value.items).to eq([project3, project2, project1]) end end end context 'with unauthorized user' do - let(:current_user) { create(:user) } + let_it_be(:current_user) { create(:user) } it { is_expected.to be_nil } end diff --git a/spec/requests/api/graphql/ci/runner_spec.rb b/spec/requests/api/graphql/ci/runner_spec.rb index 032c167a2c8526077889e91be2846ea7924670f5..a2fb646769b2cc706221fb582c2c27cfc5cb6f9f 100644 --- a/spec/requests/api/graphql/ci/runner_spec.rb +++ b/spec/requests/api/graphql/ci/runner_spec.rb @@ -818,8 +818,8 @@ 'projectCount' => 2, 'projects' => { 'nodes' => [ - a_graphql_entity_for(project1), - a_graphql_entity_for(project2) + a_graphql_entity_for(project2), + a_graphql_entity_for(project1) ] }) expect(runner2_data).to match a_hash_including(