lib/graphql/relay/base_connection.rb in graphql-relay-0.10.0 vs lib/graphql/relay/base_connection.rb in graphql-relay-0.11.0
- old
+ new
@@ -12,28 +12,14 @@
#
class BaseConnection
# Just to encode data in the cursor, use something that won't conflict
CURSOR_SEPARATOR = "---"
- # Map of collection classes -> connection_classes
- # eg Array -> ArrayConnection
+ # Map of collection class names -> connection_classes
+ # eg {"Array" => ArrayConnection}
CONNECTION_IMPLEMENTATIONS = {}
- # Create a connection which exposes edges of this type
- def self.create_type(wrapped_type, &block)
- edge_type = wrapped_type.edge_type
-
- connection_type = ObjectType.define do
- name("#{wrapped_type.name}Connection")
- field :edges, types[edge_type]
- field :pageInfo, PageInfo, property: :page_info
- block && instance_eval(&block)
- end
-
- connection_type
- end
-
# Find a connection implementation suitable for exposing `items`
#
# @param [Object] A collection of items (eg, Array, AR::Relation)
# @return [subclass of BaseConnection] a connection Class for wrapping `items`
def self.connection_for_items(items)
@@ -59,20 +45,22 @@
# @param [Class] A class implementing Connection methods
def self.register_connection_implementation(items_class, connection_class)
CONNECTION_IMPLEMENTATIONS[items_class.name] = connection_class
end
- attr_reader :object, :arguments, :max_page_size
+ attr_reader :object, :arguments, :max_page_size, :parent
# Make a connection, wrapping `object`
# @param The collection of results
# @param Query arguments
# @param max_page_size [Int] The maximum number of results to return
- def initialize(object, arguments, max_page_size: nil)
+ # @param parent [Object] The object which this collection belongs to
+ def initialize(object, arguments, max_page_size: nil, parent: nil)
@object = object
@arguments = arguments
@max_page_size = max_page_size
+ @parent = parent
end
# Provide easy access to provided arguments:
METHODS_FROM_ARGUMENTS = [:first, :after, :last, :before, :order]
@@ -90,12 +78,13 @@
define_method(arg_name) do
arguments[arg_name]
end
end
- # Wrap nodes in {Edge}s so they expose cursors.
- def edges
- @edges ||= paged_nodes.map { |item| Edge.new(item, self) }
+ # These are the items to render for this connection,
+ # probably wrapped by {GraphQL::Relay::Edge}
+ def edge_nodes
+ @edge_nodes ||= paged_nodes
end
# Support the `pageInfo` field
def page_info
self