Commit 0b47d540 authored by Tiger's avatar Tiger

Add lookahead preloading for cluster agent tokens

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40779
parent 28c3d8d4
......@@ -101,6 +101,7 @@ module EE
field :cluster_agents,
::Types::Clusters::AgentType.connection_type,
extras: [:lookahead],
null: true,
description: 'Cluster agents associated with the project',
resolver: ::Resolvers::Clusters::AgentsResolver
......
......@@ -3,14 +3,24 @@
module Resolvers
module Clusters
class AgentsResolver < BaseResolver
include LooksAhead
type Types::Clusters::AgentType, null: true
alias_method :project, :object
def resolve(**args)
::Clusters::AgentsFinder
.new(project, context[:current_user], params: args)
.execute
def resolve_with_lookahead(**args)
apply_lookahead(
::Clusters::AgentsFinder
.new(project, context[:current_user], params: args)
.execute
)
end
private
def preloads
{ tokens: :agent_tokens }
end
end
end
......
......@@ -5,24 +5,36 @@ require 'spec_helper'
RSpec.describe Resolvers::Clusters::AgentsResolver do
include GraphqlHelpers
it { expect(described_class).to be < LooksAhead }
it { expect(described_class.type).to eq(Types::Clusters::AgentType) }
it { expect(described_class.null).to be_truthy }
describe '#resolve' do
let_it_be(:user) { create(:user) }
let(:finder) { double(execute: :result) }
let(:finder) { double(execute: relation) }
let(:relation) { double }
let(:project) { create(:project) }
let(:args) { Hash(key: 'value') }
let(:ctx) { Hash(current_user: user) }
subject { resolve(described_class, obj: project, args: args, ctx: ctx) }
let(:lookahead) do
double(selects?: true).tap do |selection|
allow(selection).to receive(:selection).and_return(selection)
end
end
subject { resolve(described_class, obj: project, args: args.merge(lookahead: lookahead), ctx: ctx) }
it 'calls the agents finder' do
expect(::Clusters::AgentsFinder).to receive(:new)
.with(project, user, params: args).and_return(finder)
expect(subject).to eq(:result)
expect(relation).to receive(:preload)
.with(:agent_tokens).and_return(relation)
expect(subject).to eq(relation)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment