Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekmiyani committed Jun 14, 2024
1 parent aafe132 commit ecbc222
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/phantom/graphql/field_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ def resolve(context:, object:, arguments:, **_rest)
end

class PreloadExtension < GraphQL::Schema::FieldExtension
def resolve(context:, object:, arguments:, **rest)
def resolve(context:, object:, arguments:, **rest) # rubocop:disable Metrics/AbcSize
BatchLoader::GraphQL.for(object).batch(key: field) do |records, loader|
scope = options[:scope].constantize.new(context[:current_session]).scope if options[:scope].present?
ActiveRecord::Associations::Preloader.new(records: records.map(&:object), associations: options[:preload]).call
ActiveRecord::Associations::Preloader.new(
records: records.map(&:object), associations: options[:preload], scope: scope
).call
records.each { |r| loader.call(r, super(context: context, object: r, arguments: arguments, **rest)) }
end
end
Expand All @@ -27,7 +29,10 @@ def initialize(*args, authorize: nil, preload: nil, scope: nil, **kwargs, &block
extensions = (kwargs[:extensions] ||= [])

extensions << { Phantom::Graphql::FieldExtensions::AuthorizeExtension => authorize } if authorize.present?
extensions << { Phantom::Graphql::FieldExtensions::PreloadExtension => { preload: preload, scope: scope } } if preload.present?

if preload.present?
extensions << { Phantom::Graphql::FieldExtensions::PreloadExtension => { preload: preload, scope: scope } }
end

super(*args, **kwargs, &block)
end
Expand Down

0 comments on commit ecbc222

Please sign in to comment.