summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/issues_resolver.rb
blob: 850df2885aa0e86fb8096d737f0f71b11735f82f (plain)
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
# frozen_string_literal: true

module Resolvers
  class IssuesResolver < BaseResolver
    argument :iid, GraphQL::STRING_TYPE,
              required: false,
              description: 'The IID of the issue, e.g., "1"'

    argument :iids, [GraphQL::STRING_TYPE],
              required: false,
              description: 'The list of IIDs of issues, e.g., [1, 2]'
    argument :state, Types::IssuableStateEnum,
              required: false,
              description: 'Current state of Issue'
    argument :label_name, GraphQL::STRING_TYPE.to_list_type,
              required: false,
              description: 'Labels applied to the Issue'
    argument :created_before, Types::TimeType,
              required: false,
              description: 'Issues created before this date'
    argument :created_after, Types::TimeType,
              required: false,
              description: 'Issues created after this date'
    argument :updated_before, Types::TimeType,
              required: false,
              description: 'Issues updated before this date'
    argument :updated_after, Types::TimeType,
              required: false,
              description: 'Issues updated after this date'
    argument :closed_before, Types::TimeType,
              required: false,
              description: 'Issues closed before this date'
    argument :closed_after, Types::TimeType,
              required: false,
              description: 'Issues closed after this date'
    argument :search, GraphQL::STRING_TYPE, # rubocop:disable Graphql/Descriptions
              required: false
    argument :sort, Types::SortEnum,
              description: 'Sort issues by this criteria',
              required: false,
              default_value: 'created_desc'

    type Types::IssueType, null: true

    def resolve(**args)
      # The project could have been loaded in batch by `BatchLoader`.
      # At this point we need the `id` of the project to query for issues, so
      # make sure it's loaded and not `nil` before continuing.
      project = object.respond_to?(:sync) ? object.sync : object
      return Issue.none if project.nil?

      # Will need to be be made group & namespace aware with
      # https://gitlab.com/gitlab-org/gitlab-foss/issues/54520
      args[:project_id] = project.id
      args[:iids] ||= [args[:iid]].compact

      IssuesFinder.new(context[:current_user], args).execute
    end

    def self.resolver_complexity(args, child_complexity:)
      complexity = super
      complexity += 2 if args[:labelName]

      complexity
    end
  end
end