Module: GraphQL::Relay::ConnectionType

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

Class Method Summary collapse

Class Method Details

.create_type(wrapped_type, edge_type: nil, edge_class: nil, &block) ⇒ Object

Create a connection which exposes edges of this type



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/graphql/relay/connection_type.rb', line 5

def self.create_type(wrapped_type, edge_type: nil, edge_class: nil, &block)
  edge_type ||= wrapped_type.edge_type
  edge_class ||= GraphQL::Relay::Edge
  connection_type_name = "#{wrapped_type.name}Connection"

  connection_type = ObjectType.define do
    name(connection_type_name)
    field :edges, types[edge_type] do
      resolve -> (obj, args, ctx) {
        obj.edge_nodes.map { |item| edge_class.new(item, obj) }
      }
    end
    field :pageInfo, !PageInfo, property: :page_info
    block && instance_eval(&block)
  end

  connection_type
end