lib/graphql/relay/edges_instrumentation.rb in graphql-1.8.3 vs lib/graphql/relay/edges_instrumentation.rb in graphql-1.8.4

- old
+ new

@@ -2,54 +2,38 @@ module GraphQL module Relay module EdgesInstrumentation def self.instrument(type, field) if field.edges? - edges_resolve = EdgesResolve.new( - edge_class: field.edge_class, - resolve: field.resolve_proc, - lazy_resolve: field.lazy_resolve_proc, - ) + edges_resolve = EdgesResolve.new(edge_class: field.edge_class, resolve: field.resolve_proc) + edges_lazy_resolve = EdgesResolve.new(edge_class: field.edge_class, resolve: field.lazy_resolve_proc) field.redefine( - resolve: edges_resolve.method(:resolve), - lazy_resolve: edges_resolve.method(:lazy_resolve), + resolve: edges_resolve, + lazy_resolve: edges_lazy_resolve, ) else field end end class EdgesResolve - def initialize(edge_class:, resolve:, lazy_resolve:) + def initialize(edge_class:, resolve:) @edge_class = edge_class @resolve_proc = resolve - @lazy_resolve_proc = lazy_resolve end # A user's custom Connection may return a lazy object, # if so, handle it later. - def resolve(obj, args, ctx) + def call(obj, args, ctx) + parent = ctx.object nodes = @resolve_proc.call(obj, args, ctx) if ctx.schema.lazy?(nodes) - ConnectionResolve::LazyNodesWrapper.new(obj, nodes) + nodes else - build_edges(nodes, obj) + nodes.map { |item| @edge_class.new(item, parent) } end - end - - # If we get this far, unwrap the wrapper, - # resolve the lazy object and make the edges as usual - def lazy_resolve(obj, args, ctx) - items = @lazy_resolve_proc.call(obj.lazy_object, args, ctx) - build_edges(items, obj.parent) - end - - private - - def build_edges(items, connection) - items.map { |item| @edge_class.new(item, connection) } end end end end end