1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# frozen_string_literal: true
module Resolvers
module WorkItems
class WorkItemDiscussionsResolver < BaseResolver
include Gitlab::Graphql::Authorize::AuthorizeResource
extension Gitlab::Graphql::Extensions::ForwardOnlyExternallyPaginatedArrayExtension
authorize :read_work_item
authorizes_object!
# this resolver may be calling gitaly as part of parsing notes that contain commit references
calls_gitaly!
alias_method :notes_widget, :object
argument :filter, Types::WorkItems::NotesFilterTypeEnum,
required: false,
default_value: Types::WorkItems::NotesFilterTypeEnum.default_value,
description: 'Type of notes collection: ALL_NOTES, ONLY_COMMENTS, ONLY_ACTIVITY.'
type Types::Notes::DiscussionType.connection_type, null: true
def resolve(**args)
finder = Issuable::DiscussionsListService.new(current_user, work_item, params(args))
Gitlab::Graphql::ExternallyPaginatedArray.new(
finder.paginator.cursor_for_previous_page,
finder.paginator.cursor_for_next_page,
*finder.execute
)
end
def self.field_options
# we manage the pagination manually through external array, so opt out of the connection field extension
super.merge(connection: false)
end
def self.calculate_ext_conn_complexity
true
end
def self.complexity_multiplier(args)
0.05
end
private
def work_item
notes_widget.work_item
end
strong_memoize_attr :work_item
def params(args)
{
notes_filter: args[:filter],
cursor: args[:after],
per_page: self.class.nodes_limit(args, @field, context: context)
}
end
def self.nodes_limit(args, field, **kwargs)
page_size = field&.max_page_size || kwargs[:context]&.schema&.default_max_page_size
[args[:first], page_size].compact.min
end
end
end
end
|