debian-mirror-gitlab/app/graphql/resolvers/full_path_resolver.rb

22 lines
697 B
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
module Resolvers
module FullPathResolver
extend ActiveSupport::Concern
prepended do
argument :full_path, GraphQL::ID_TYPE,
required: true,
description: 'The full path of the project or namespace, e.g., "gitlab-org/gitlab-ce"'
end
def model_by_full_path(model, full_path)
2019-01-03 12:48:30 +05:30
BatchLoader.for(full_path).batch(key: "#{model.model_name.param_key}:full_path") do |full_paths, loader|
2018-11-08 19:23:39 +05:30
# `with_route` avoids an N+1 calculating full_path
2019-01-03 12:48:30 +05:30
results = model.where_full_path_in(full_paths).with_route
results.each { |project| loader.call(project.full_path, project) }
2018-11-08 19:23:39 +05:30
end
end
end
end