Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_parent_resolver.rb « issues « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6308e56f0490875d78f201fba6089d1f62188a86 (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
# frozen_string_literal: true

module Resolvers
  module Issues
    class BaseParentResolver < Issues::BaseResolver
      prepend ::Issues::LookAheadPreloads
      include ::Issues::SortArguments

      argument :state, Types::IssuableStateEnum,
                required: false,
                description: 'Current state of this issue.'

      # see app/graphql/types/issue_connection.rb
      type 'Types::IssueConnection', null: true

      def resolve_with_lookahead(**args)
        return Issue.none if resource_parent.nil?

        finder = IssuesFinder.new(current_user, prepare_finder_params(args))

        issues = Gitlab::Graphql::Loaders::IssuableLoader.new(resource_parent, finder).batching_find_all do |q|
          apply_lookahead(q)
        end

        if non_stable_cursor_sort?(args[:sort])
          # Certain complex sorts are not supported by the stable cursor pagination yet.
          # In these cases, we use offset pagination, so we return the correct connection.
          offset_pagination(issues)
        else
          issues
        end
      end

      private

      def resource_parent
        # 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.
        strong_memoize(:resource_parent) do
          object.respond_to?(:sync) ? object.sync : object
        end
      end
    end
  end
end

Resolvers::Issues::BaseParentResolver.prepend_mod