Class: GraphQLIncludable::Relay::Instrumentation::Connection
- Inherits:
-
Object
- Object
- GraphQLIncludable::Relay::Instrumentation::Connection
- Defined in:
- lib/graphql_includable/relay/instrumentation/connection.rb
Instance Method Summary collapse
-
#instrument(_type, field) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#instrument(_type, field) ⇒ Object
rubocop:disable Metrics/AbcSize
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/graphql_includable/relay/instrumentation/connection.rb', line 6 def instrument(_type, field) return field unless edge_with_node_connection?(field) raise ArgumentError, 'Connection does not support fetching using :property' if field.property.present? validate!(field) edge_to_node_property = field.[:edge_to_node_property] explicit_includes = field.[:includes] edges_prop = explicit_includes[:edges] nodes_prop = explicit_includes[:nodes] if proc_based?(field) edges_resolver = field.[:resolve_edges] nodes_resolver = field.[:resolve_nodes] else # Use the edges and nodes symbols from the incldues pattern as the propeties to fetch edges_resolver = ->(obj, _args, _ctx) { obj.public_send(edges_prop) } nodes_resolver = ->(obj, _args, _ctx) { obj.public_send(nodes_prop) } end _original_resolve = field.resolve_proc new_resolve_proc = ->(obj, args, ctx) do ConnectionEdgesAndNodes.new(obj, args, ctx, edges_prop, nodes_prop, edge_to_node_property, edges_resolver, nodes_resolver) end field.redefine { resolve(new_resolve_proc) } end |