Module: GraphQL::Preload::FieldMetadata

Included in:
GraphQL
Defined in:
lib/graphql/preload.rb

Instance Method Summary collapse

Instance Method Details

#initialize(*args, preload: nil, preload_scope: nil, **kwargs, &block) ⇒ Object


33
34
35
36
37
# File 'lib/graphql/preload.rb', line 33

def initialize(*args, preload: nil, preload_scope: nil, **kwargs, &block)
  super(*args, **kwargs, &block)
  self.preload(preload) if preload
  self.preload_scope(preload_scope) if preload_scope
end

#preload(associations) ⇒ Object


39
40
41
42
# File 'lib/graphql/preload.rb', line 39

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

#preload_scope(scope_proc) ⇒ Object


44
45
46
# File 'lib/graphql/preload.rb', line 44

def preload_scope(scope_proc)
  @preload_scope = scope_proc
end

#to_graphqlObject


48
49
50
51
52
53
# File 'lib/graphql/preload.rb', line 48

def to_graphql
  field_defn = super
  field_defn.[:preload] = @preload
  field_defn.[:preload_scope] = @preload_scope
  field_defn
end