Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/graphql/preload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ def enable_preloading

module FieldMetadata
def initialize(*args, preload: nil, preload_scope: nil, **kwargs, &block)
if preload
@preload ||= []
@preload.concat Array.wrap preload
end
if preload_scope
@preload_scope = preload_scope
end
super(*args, **kwargs, &block)
self.preload(preload) if preload
self.preload_scope(preload_scope) if preload_scope
end

def preload(associations)
@preload ||= []
@preload.concat Array.wrap associations
end

def preload_scope(scope_proc)
@preload_scope = scope_proc
end

def to_graphql
Expand Down