class GraphQR::Pagination::PaginationExtension

The PaginationExtension is used on the GraphQR::Fields::BaseField.

It adds the per and page arguments to the paginated field and uses the selected paginator resolver to add nodes, edges and page_info on the response

Constants

INVALID_PAGINATOR_ERROR
NO_PAGINATOR_ERROR

Public Instance Methods

after_resolve(value:, arguments:, **_kwargs) click to toggle source
# File lib/graphqr/pagination/pagination_extension.rb, line 29
def after_resolve(value:, arguments:, **_kwargs)
  raise GraphQL::ExecutionError, NO_PAGINATOR_ERROR unless GraphQR.paginator.present?

  call_resolver(value, arguments)
end
apply() click to toggle source
# File lib/graphqr/pagination/pagination_extension.rb, line 14
def apply
  field.argument :per, 'Int', required: false, default_value: 25,
                              description: 'The requested number of nodes for the page'
  field.argument :page, 'Int', required: false, default_value: 1,
                               description: 'The requested page number'
end
call_resolver(value, arguments) click to toggle source
# File lib/graphqr/pagination/pagination_extension.rb, line 35
def call_resolver(value, arguments)
  case GraphQR.paginator
  when :pagy
    Resolvers::PagyResolver.new(value, items: arguments[:per], page: arguments[:page])
  else
    raise GraphQL::ExecutionError, INVALID_PAGINATOR_ERROR
  end
end
resolve(object:, arguments:, **_kwargs) { |object, next_args| ... } click to toggle source

Remove pagination args before passing it to a user method

# File lib/graphqr/pagination/pagination_extension.rb, line 22
def resolve(object:, arguments:, **_kwargs)
  next_args = arguments.dup
  next_args.delete(:per)
  next_args.delete(:page)
  yield(object, next_args)
end