Class: GraphQLIncludable::Relay::EdgeWithNodeConnectionType

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

Class Method Summary collapse

Class Method Details

.create_type(wrapped_type, edge_to_node_property:, edge_type: wrapped_type.edge_type, edge_class: EdgeWithNode, nodes_field: GraphQL::Relay::ConnectionType.default_nodes_field, &block) ⇒ Object



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

def self.create_type(
  wrapped_type, edge_to_node_property:,
  edge_type: wrapped_type.edge_type, edge_class: EdgeWithNode, nodes_field: GraphQL::Relay::ConnectionType.default_nodes_field, &block
)
  custom_edge_class = edge_class

  GraphQL::ObjectType.define do
    name("#{wrapped_type.name}Connection")
    description("The connection type for #{wrapped_type.name}.")
    field :edges, types[edge_type], "A list of edges.", edge_class: custom_edge_class, property: :fetch_edges, edge_to_node_property: edge_to_node_property

    if nodes_field
      field :nodes, types[wrapped_type],  "A list of nodes.", property: :fetch_nodes
    end

    field :pageInfo, !GraphQL::Relay::PageInfo, "Information to aid in pagination.", property: :page_info
    block && instance_eval(&block)
  end
end