Commit bc802e4b authored by briankabiro's avatar briankabiro

Fix merge request GraphQL resolver

The resolver doesn't respond to pagination params such as `first`
Additionally, the resolver returns merge requests that belong to
all projects.

* update resolver to accept pagination params e.g `first`
* return only merge requests that belong to a project
parent 99a5a587
...@@ -20,8 +20,17 @@ module Resolvers ...@@ -20,8 +20,17 @@ module Resolvers
args[:iids] ||= [args[:iid]].compact args[:iids] ||= [args[:iid]].compact
args[:iids].map { |iid| batch_load(iid) } if args[:iids].any?
.select(&:itself) # .compact doesn't work on BatchLoader batch_load_merge_requests(args[:iids])
else
args[:project_id] = project.id
MergeRequestsFinder.new(context[:current_user], args).execute
end
end
def batch_load_merge_requests(iids)
iids.map { |iid| batch_load(iid) }.select(&:itself) # .compact doesn't work on BatchLoader
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
---
title: Fix pagination in Merge Request GraphQL api
merge_request: 28667
author: briankabiro
type: fixed
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe 'getting notes for a merge request' do describe 'getting notes for a merge request' do
include GraphqlHelpers include GraphqlHelpers
let(:noteable) { create(:merge_request) } let_it_be(:noteable) { create(:merge_request) }
def noteable_query(noteable_fields) def noteable_query(noteable_fields)
<<~QRY <<~QRY
......
...@@ -93,4 +93,41 @@ describe 'getting merge request information nested in a project' do ...@@ -93,4 +93,41 @@ describe 'getting merge request information nested in a project' do
expect(merge_request_graphql_data['pipelines']['edges'].size).to eq(1) expect(merge_request_graphql_data['pipelines']['edges'].size).to eq(1)
end end
end end
context 'when limiting the number of results' do
let(:merge_requests_graphql_data) { graphql_data['project']['mergeRequests']['edges'] }
let!(:merge_requests) do
[
create(:merge_request, source_project: project, source_branch: 'branch-1'),
create(:merge_request, source_project: project, source_branch: 'branch-2'),
create(:merge_request, source_project: project, source_branch: 'branch-3')
]
end
let(:fields) do
<<~QUERY
edges {
node {
iid,
title
}
}
QUERY
end
let(:query) do
graphql_query_for(
'project',
{ 'fullPath' => project.full_path },
"mergeRequests(first: 2) { #{fields} }"
)
end
it 'returns the correct number of results' do
post_graphql(query, current_user: current_user)
expect(merge_requests_graphql_data.size).to eq 2
end
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