Class: GraphQR::Pagination::PaginationExtension
- Inherits:
-
GraphQL::Schema::FieldExtension
- Object
- GraphQL::Schema::FieldExtension
- GraphQR::Pagination::PaginationExtension
- Defined in:
- lib/graphqr/pagination/pagination_extension.rb
Overview
TODO: add documentation
Constant Summary collapse
- DEFAULT_PAGINATION_ERROR =
'No paginator defined'
Instance Method Summary collapse
- #after_resolve(value:, arguments:, **_kwargs) ⇒ Object
- #apply ⇒ Object
-
#resolve(object:, arguments:, **_kwargs) {|object, next_args| ... } ⇒ Object
Remove pagination args before passing it to a user method.
Instance Method Details
#after_resolve(value:, arguments:, **_kwargs) ⇒ Object
25 26 27 28 29 |
# File 'lib/graphqr/pagination/pagination_extension.rb', line 25 def after_resolve(value:, arguments:, **_kwargs) raise GraphQL::ExecutionError, DEFAULT_PAGINATION_ERROR unless GraphQR.paginator.present? Resolvers::PagyResolver.new(value, items: arguments[:per], page: arguments[:page]) if GraphQR.use_pagy? end |
#apply ⇒ Object
10 11 12 13 14 15 |
# File 'lib/graphqr/pagination/pagination_extension.rb', line 10 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 |
#resolve(object:, arguments:, **_kwargs) {|object, next_args| ... } ⇒ Object
Remove pagination args before passing it to a user method
18 19 20 21 22 23 |
# File 'lib/graphqr/pagination/pagination_extension.rb', line 18 def resolve(object:, arguments:, **_kwargs) next_args = arguments.dup next_args.delete(:per) next_args.delete(:page) yield(object, next_args) end |