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

full_path_resolver.rb « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 46d3360baaea2ede6570ed5bf312dfb9df1c0c68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Resolvers
  module FullPathResolver
    extend ActiveSupport::Concern

    prepended do
      argument :full_path, GraphQL::ID_TYPE,
               required: true,
               description: 'The full path of the project, group or namespace, e.g., "gitlab-org/gitlab-foss"'
    end

    def model_by_full_path(model, full_path)
      BatchLoader::GraphQL.for(full_path).batch(key: model) do |full_paths, loader, args|
        # `with_route` avoids an N+1 calculating full_path
        args[:key].where_full_path_in(full_paths).with_route.each do |model_instance|
          loader.call(model_instance.full_path, model_instance)
        end
      end
    end
  end
end