Commit da32e10d authored by James Lopez's avatar James Lopez

Merge branch '34527-fix-graphql-endpoint-for-merge-requests' into 'master'

Fix merge request GraphQL resolver

See merge request gitlab-org/gitlab!28667
parents 837a6b53 bc802e4b
......@@ -20,8 +20,17 @@ module Resolvers
args[:iids] ||= [args[:iid]].compact
args[:iids].map { |iid| batch_load(iid) }
.select(&:itself) # .compact doesn't work on BatchLoader
if args[:iids].any?
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
# 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'
describe 'getting notes for a merge request' do
include GraphqlHelpers
let(:noteable) { create(:merge_request) }
let_it_be(:noteable) { create(:merge_request) }
def noteable_query(noteable_fields)
<<~QRY
......
......@@ -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)
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
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