Class: GraphQL::Relay::ConnectionResolve

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/relay/connection_resolve.rb

Defined Under Namespace

Classes: LazyNodesWrapper

Instance Method Summary collapse

Constructor Details

#initialize(field, underlying_resolve, lazy:) ⇒ ConnectionResolve

Returns a new instance of ConnectionResolve.



5
6
7
8
9
10
# File 'lib/graphql/relay/connection_resolve.rb', line 5

def initialize(field, underlying_resolve, lazy:)
  @field = field
  @underlying_resolve = underlying_resolve
  @max_page_size = field.connection_max_page_size
  @lazy = lazy
end

Instance Method Details

#call(obj, args, ctx) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/graphql/relay/connection_resolve.rb', line 12

def call(obj, args, ctx)
  if @lazy && obj.is_a?(LazyNodesWrapper)
    parent = obj.parent
    obj = obj.lazy_object
  else
    parent = obj
  end

  nodes = @underlying_resolve.call(obj, args, ctx)

  if nodes.nil?
    nil
  elsif ctx.schema.lazy?(nodes)
    if !@lazy
      LazyNodesWrapper.new(obj, nodes)
    else
      nodes
    end
  elsif nodes.is_a?(GraphQL::Execution::Execute::Skip)
    nodes
  else
    build_connection(nodes, args, parent, ctx)
  end
end