Class: GraphQL::Relay::EdgesInstrumentation::EdgesResolve

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

Instance Method Summary collapse

Constructor Details

#initialize(edge_class:, resolve:, lazy_resolve:) ⇒ EdgesResolve

Returns a new instance of EdgesResolve



24
25
26
27
28
# File 'lib/graphql/relay/edges_instrumentation.rb', line 24

def initialize(edge_class:, resolve:, lazy_resolve:)
  @edge_class = edge_class
  @resolve_proc = resolve
  @lazy_resolve_proc = lazy_resolve
end

Instance Method Details

#lazy_resolve(obj, args, ctx) ⇒ Object

If we get this far, unwrap the wrapper, resolve the lazy object and make the edges as usual



43
44
45
46
# File 'lib/graphql/relay/edges_instrumentation.rb', line 43

def lazy_resolve(obj, args, ctx)
  items = @lazy_resolve_proc.call(obj.lazy_object, args, ctx)
  build_edges(items, obj.parent)
end

#resolve(obj, args, ctx) ⇒ Object

A user’s custom Connection may return a lazy object, if so, handle it later.



32
33
34
35
36
37
38
39
# File 'lib/graphql/relay/edges_instrumentation.rb', line 32

def resolve(obj, args, ctx)
  nodes = @resolve_proc.call(obj, args, ctx)
  if ctx.schema.lazy?(nodes)
    ConnectionResolve::LazyNodesWrapper.new(obj, nodes)
  else
    build_edges(nodes, obj)
  end
end