Class: GraphQLIncludable::Relay::Instrumentation::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_includable/relay/instrumentation/connection.rb

Instance Method Summary collapse

Instance Method Details

#instrument(_type, field) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/graphql_includable/relay/instrumentation/connection.rb', line 5

def instrument(_type, field)
  return field unless field.connection?

   = [:edges_property, :nodes_property]
  requires_instrumentation = .any? { |key| field..key?(key) }

  return field unless requires_instrumentation
  raise ArgumentError unless .all? { |key| field..key?(key) }

  raise ArgumentError if field.property.present? # TODO: Check for resolve proc too

  edges_prop = field.[:edges_property]
  nodes_prop = field.[:nodes_property]

  _original_resolve = field.resolve_proc
  new_resolve_proc = ->(obj, args, ctx) do
    ConnectionEdgesAndNodes.new(obj, edges_prop, nodes_prop)
  end

  field.redefine { resolve(new_resolve_proc) }
end