gitlab-org--gitlab-foss/app/graphql/resolvers/merge_requests_resolver.rb
Bob Van Landuyt f16b13113f Fix incorrect instances of GraphQL::ID_TYPE
Since the `GraphQL::ID_TYPE` usages should represent globally unique
ids, this changes some fields for which this is not the case into
strings.

The `ID_TYPE` is a specialised, so this change should be backwards
compatible.

https://graphql-ruby.org/type_definitions/scalars.html
2019-06-03 21:59:33 +02:00

36 lines
1 KiB
Ruby

# frozen_string_literal: true
module Resolvers
class MergeRequestsResolver < BaseResolver
argument :iid, GraphQL::STRING_TYPE,
required: false,
description: 'The IID of the merge request, e.g., "1"'
argument :iids, [GraphQL::STRING_TYPE],
required: false,
description: 'The list of IIDs of issues, e.g., [1, 2]'
type Types::MergeRequestType, null: true
alias_method :project, :object
def resolve(**args)
return unless project.present?
args[:iids] ||= [args[:iid]].compact
args[:iids].map { |iid| batch_load(iid) }
.select(&:itself) # .compact doesn't work on BatchLoader
end
# rubocop: disable CodeReuse/ActiveRecord
def batch_load(iid)
BatchLoader.for(iid.to_s).batch(key: project) do |iids, loader, args|
args[:key].merge_requests.where(iid: iids).each do |mr|
loader.call(mr.iid.to_s, mr)
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end