module GraphQL::KaminariConnection::ClassMethods

Public Instance Methods

base_page_class() click to toggle source

@return [Class]

# File lib/graphql/kaminari_connection.rb, line 71
def base_page_class
  GraphQL::Schema::Object
end
kaminari_connection(without_count: false, **params) click to toggle source
# File lib/graphql/kaminari_connection.rb, line 62
def kaminari_connection(without_count: false, **params)
  {
    type: without_count ? page_type_without_count : page_type,
    arguments: page_arguments,
    null: false
  }.merge(params)
end

Private Instance Methods

define_page_type(without_count:) click to toggle source

@param without_count [Boolean] @return [Class]

# File lib/graphql/kaminari_connection.rb, line 96
def define_page_type(without_count:)
  type_name = without_count ? "#{graphql_name}PageWithoutTotalPages" : "#{graphql_name}Page"
  type_class = self
  page_data_type_class =
    without_count ? KaminariConnection.page_data_without_count_type : KaminariConnection.page_data_type

  Class.new(base_page_class) do
    graphql_name type_name
    description "Autogenerated page type for #{type_name}"

    field :page_data, page_data_type_class, null: false, method: :object
    field :items, [type_class], 'A list of items', null: false, method: :object
  end
end
page_arguments() click to toggle source
# File lib/graphql/kaminari_connection.rb, line 87
def page_arguments
  [
    [:page, type: 'Int', required: false],
    [:per, type: 'Int', required: false]
  ]
end
page_type() click to toggle source

@return [Class]

# File lib/graphql/kaminari_connection.rb, line 83
def page_type
  @page_type ||= define_page_type(without_count: false)
end
page_type_without_count() click to toggle source

@return [Class]

# File lib/graphql/kaminari_connection.rb, line 78
def page_type_without_count
  @page_type_without_count ||= define_page_type(without_count: true)
end