2018-05-23 03:55:14 -04:00
|
|
|
module Resolvers
|
|
|
|
module FullPathResolver
|
|
|
|
extend ActiveSupport::Concern
|
2018-02-23 10:36:40 -05:00
|
|
|
|
2018-05-23 03:55:14 -04:00
|
|
|
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"'
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
|
2018-02-23 10:36:40 -05:00
|
|
|
def model_by_full_path(model, full_path)
|
|
|
|
BatchLoader.for(full_path).batch(key: "#{model.model_name.param_key}:full_path") do |full_paths, loader|
|
|
|
|
# `with_route` avoids an N+1 calculating full_path
|
|
|
|
results = model.where_full_path_in(full_paths).with_route
|
|
|
|
results.each { |project| loader.call(project.full_path, project) }
|
|
|
|
end
|
|
|
|
end
|
2017-08-16 09:04:41 -04:00
|
|
|
end
|
|
|
|
end
|