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

field_extension.rb « todos_project_permission_preloader « graphql « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 77f3b1ac71af9535e3a2146c7ef3b60fd356c7a4 (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
# frozen_string_literal: true

module Gitlab
  module Graphql
    module TodosProjectPermissionPreloader
      class FieldExtension < ::GraphQL::Schema::FieldExtension
        def after_resolve(value:, memo:, **rest)
          todos = value.to_a

          Preloaders::UserMaxAccessLevelInProjectsPreloader.new(
            todos.map(&:project).compact,
            current_user(rest)
          ).execute

          value
        end

        private

        def current_user(options)
          options.dig(:context, :current_user)
        end
      end
    end
  end
end