Module: LooksAhead

Extended by:
ActiveSupport::Concern
Included in:
Resolvers::AlertManagement::AlertResolver, Resolvers::Ci::PipelineStagesResolver, ResolvesMergeRequests
Defined in:
app/graphql/resolvers/concerns/looks_ahead.rb

Constant Summary collapse

FEATURE_FLAG =
:graphql_lookahead_support

Instance Method Summary collapse

Instance Method Details

#apply_lookahead(query) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/graphql/resolvers/concerns/looks_ahead.rb', line 18

def apply_lookahead(query)
  return query unless Feature.enabled?(FEATURE_FLAG)

  selection = node_selection

  includes = preloads.each.flat_map do |name, requirements|
    selection&.selects?(name) ? requirements : []
  end
  preloads = (unconditional_includes + includes).uniq

  return query if preloads.empty?

  query.preload(*preloads) # rubocop: disable CodeReuse/ActiveRecord
end

#resolve(**args) ⇒ Object


12
13
14
15
16
# File 'app/graphql/resolvers/concerns/looks_ahead.rb', line 12

def resolve(**args)
  self.lookahead = args.delete(:lookahead)

  resolve_with_lookahead(**args)
end