2021-06-08 01:23:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
module Ci
|
|
|
|
class RunnerResolver < BaseResolver
|
|
|
|
include LooksAhead
|
|
|
|
|
|
|
|
type Types::Ci::RunnerType, null: true
|
|
|
|
extras [:lookahead]
|
|
|
|
description 'Runner information.'
|
|
|
|
|
|
|
|
argument :id,
|
|
|
|
type: ::Types::GlobalIDType[::Ci::Runner],
|
|
|
|
required: true,
|
|
|
|
description: 'Runner ID.'
|
|
|
|
|
|
|
|
def resolve_with_lookahead(id:)
|
|
|
|
find_runner(id: id)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_runner(id:)
|
|
|
|
runner_id = GitlabSchema.parse_gid(id, expected_type: ::Ci::Runner).model_id.to_i
|
2023-05-27 22:25:52 +05:30
|
|
|
key = {
|
|
|
|
preload_tag_list: lookahead.selects?(:tag_list),
|
|
|
|
preload_creator: lookahead.selects?(:created_by)
|
|
|
|
}
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
BatchLoader::GraphQL.for(runner_id).batch(key: key) do |ids, loader, batch|
|
2021-06-08 01:23:25 +05:30
|
|
|
results = ::Ci::Runner.id_in(ids)
|
|
|
|
results = results.with_tags if batch[:key][:preload_tag_list]
|
2023-05-27 22:25:52 +05:30
|
|
|
results = results.with_creator if batch[:key][:preload_creator]
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
results.each { |record| loader.call(record.id, record) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|