Commit 7ba295db authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '345833-fix-missing-keyset-pagination-ordering' into 'master'

Fix disappearing ORDER BY when keyset paginating

See merge request gitlab-org/gitlab!74695
parents 261bc584 a38c93c7
......@@ -9,7 +9,7 @@ module Gitlab
raise(UnsupportedScopeOrder) unless success
@cursor = cursor
@order = Gitlab::Pagination::Keyset::Order.extract_keyset_order_object(scope)
@order = Gitlab::Pagination::Keyset::Order.extract_keyset_order_object(@scope)
@use_union_optimization = in_operator_optimization_options ? false : use_union_optimization
@in_operator_optimization_options = in_operator_optimization_options
end
......
......@@ -155,7 +155,7 @@ module Gitlab
def apply_cursor_conditions(scope, values = {}, options = { use_union_optimization: false, in_operator_optimization_options: nil })
values ||= {}
transformed_values = values.with_indifferent_access
scope = apply_custom_projections(scope.dup)
scope = apply_custom_projections(scope)
where_values = build_where_values(transformed_values)
......
......@@ -96,4 +96,43 @@ RSpec.describe 'package details' do
expect(graphql_data_at(:b)).to be(nil)
end
end
context 'when loading pipelines ordered by ID DESC' do
let(:pipelines) { create_list(:ci_pipeline, 6, project: project) }
before do
composer_package.pipelines = pipelines
composer_package.save!
end
def run_query(args)
pipelines_nodes = <<~QUERY
nodes {
id
}
pageInfo {
endCursor
}
QUERY
query = graphql_query_for(:package, { id: package_global_id }, query_graphql_field("pipelines", args, pipelines_nodes))
post_graphql(query, current_user: user)
end
it 'loads the second page correctly' do
run_query({ first: 2 })
cursor = graphql_data.dig('package', 'pipelines', 'pageInfo', 'endCursor')
run_query({ first: 2, after: cursor })
expected_pipeline_ids = pipelines
.sort_by(&:id)
.reverse[2..3] # second page
.map { |pipeline| pipeline.to_gid.to_s }
pipeline_ids = graphql_data.dig('package', 'pipelines', 'nodes').pluck('id')
expect(pipeline_ids).to eq(expected_pipeline_ids)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment