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,
|
2019-12-04 20:38:33 +05:30
|
|
|
description: 'The full path of the project, group or namespace, e.g., "gitlab-org/gitlab-foss"'
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def model_by_full_path(model, full_path)
|
2019-12-04 20:38:33 +05:30
|
|
|
BatchLoader::GraphQL.for(full_path).batch(key: model) do |full_paths, loader, args|
|
2018-11-08 19:23:39 +05:30
|
|
|
# `with_route` avoids an N+1 calculating full_path
|
2019-07-31 22:56:46 +05:30
|
|
|
args[:key].where_full_path_in(full_paths).with_route.each do |model_instance|
|
|
|
|
loader.call(model_instance.full_path, model_instance)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|