class GraphqlRails::Model::BuildConnectionType

builds connection type from graphql type with some extra attributes

Attributes

initial_type[R]

Public Class Methods

new(initial_type) click to toggle source
# File lib/graphql_rails/model/build_connection_type.rb, line 16
def initialize(initial_type)
  @initial_type = initial_type
end

Public Instance Methods

call() click to toggle source
# File lib/graphql_rails/model/build_connection_type.rb, line 20
def call
  build_connection_type
end

Private Instance Methods

build_connection_type() click to toggle source
# File lib/graphql_rails/model/build_connection_type.rb, line 26
def build_connection_type
  edge_type = build_edge_type
  type = initial_type
  Class.new(GraphQL::Types::Relay::BaseConnection) do
    graphql_name("#{type.graphql_name}Connection")
    edge_type(edge_type)

    field :total, Integer, null: false

    def total
      CountItems.call(object)
    end
  end
end
build_edge_type() click to toggle source
# File lib/graphql_rails/model/build_connection_type.rb, line 41
def build_edge_type
  type = initial_type

  Class.new(GraphQL::Types::Relay::BaseEdge) do
    graphql_name("#{type.graphql_name}Edge")

    node_type(type)
  end
end
total() click to toggle source
# File lib/graphql_rails/model/build_connection_type.rb, line 35
def total
  CountItems.call(object)
end