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 ...@@ -101,6 +101,7 @@ module EE
field :cluster_agents, field :cluster_agents,
::Types::Clusters::AgentType.connection_type, ::Types::Clusters::AgentType.connection_type,
extras: [:lookahead],
null: true, null: true,
description: 'Cluster agents associated with the project', description: 'Cluster agents associated with the project',
resolver: ::Resolvers::Clusters::AgentsResolver resolver: ::Resolvers::Clusters::AgentsResolver
......
...@@ -3,14 +3,24 @@ ...@@ -3,14 +3,24 @@
module Resolvers module Resolvers
module Clusters module Clusters
class AgentsResolver < BaseResolver class AgentsResolver < BaseResolver
include LooksAhead
type Types::Clusters::AgentType, null: true type Types::Clusters::AgentType, null: true
alias_method :project, :object alias_method :project, :object
def resolve(**args) def resolve_with_lookahead(**args)
::Clusters::AgentsFinder apply_lookahead(
.new(project, context[:current_user], params: args) ::Clusters::AgentsFinder
.execute .new(project, context[:current_user], params: args)
.execute
)
end
private
def preloads
{ tokens: :agent_tokens }
end end
end end
end end
......
...@@ -5,24 +5,36 @@ require 'spec_helper' ...@@ -5,24 +5,36 @@ require 'spec_helper'
RSpec.describe Resolvers::Clusters::AgentsResolver do RSpec.describe Resolvers::Clusters::AgentsResolver do
include GraphqlHelpers include GraphqlHelpers
it { expect(described_class).to be < LooksAhead }
it { expect(described_class.type).to eq(Types::Clusters::AgentType) } it { expect(described_class.type).to eq(Types::Clusters::AgentType) }
it { expect(described_class.null).to be_truthy } it { expect(described_class.null).to be_truthy }
describe '#resolve' do describe '#resolve' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:finder) { double(execute: :result) } let(:finder) { double(execute: relation) }
let(:relation) { double }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:args) { Hash(key: 'value') } let(:args) { Hash(key: 'value') }
let(:ctx) { Hash(current_user: user) } 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 it 'calls the agents finder' do
expect(::Clusters::AgentsFinder).to receive(:new) expect(::Clusters::AgentsFinder).to receive(:new)
.with(project, user, params: args).and_return(finder) .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 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