Method: GraphQL::Relay::RangeAdd#initialize

Defined in:
lib/graphql/relay/range_add.rb

#initialize(collection:, item:, context:, parent: nil, edge_class: nil) ⇒ RangeAdd

Returns a new instance of RangeAdd.

Parameters:

  • collection (Object)

    The list of items to wrap in a connection

  • item (Object)

    The newly-added item (will be wrapped in edge_class)

  • context (GraphQL::Query::Context)

    The surrounding ctx, will be passed to the connection

  • parent (Object) (defaults to: nil)

    The owner of collection, will be passed to the connection if provided

  • edge_class (Class) (defaults to: nil)

    The class to wrap item with (defaults to the connection's edge class)

[View source] [View on GitHub]

37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/graphql/relay/range_add.rb', line 37

def initialize(collection:, item:, context:, parent: nil, edge_class: nil)
  conn_class = context.schema.connections.wrapper_for(collection)
  # The rest will be added by ConnectionExtension
  @connection = conn_class.new(collection, parent: parent, context: context, edge_class: edge_class)
  # Check if this connection supports it, to support old versions of GraphQL-Pro
  @edge = if @connection.respond_to?(:range_add_edge)
    @connection.range_add_edge(item)
  else
    @connection.edge_class.new(item, @connection)
  end

  @parent = parent
end