luckyframework / luckyframework/lucky
Paginator doesn't work outside of Actions
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 2.7k
- Forks
- 172
- PR merge metrics
- No merged PRs in 30d
Description
If you include the Lucky::Paginator::BackendHelpers module in a class that's not an action, you'll get all kinds of errors related to context or params not existing. Generally this is fine because that's where you'll set up your queries anyway. However, I'm working on an app using GraphQL, and the queries are currently happening in a GraphQL::Object.
I think we have 2 options here. I'm leaning more towards option 1, but I'll put the other option just in case...
- We add some sort of check when that module is included that if it's not an Action class, raise a compile-time error saying the paginator module doesn't work outside of Lucky::Action. Then in that error message, provide the pagination "formula"
The Lucky::Paginator is not supported outside of a Lucky::Action class.
If you need to paginate your query, try this...
offset = (page - 1) * limit
total_pages = (SomeQuery.new.select_count! / limit).ceil
SomeQuery.new.limit(limit).offset(offset)
- We refactor the the Paginator to optionally take in these http request related methods.
In the case of the graphql stuff, this still becomes a little tricky:
@[GraphQL::Field]
def followers(page : Int32, limit : Int32) : Array(UserSerializer)
end
# The paginator will look for these methods,
# but the values come through args of the previous method
def paginator_page : Int32
end
def paginator_per_page : Int32
end
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/lucky/paginator/backend_helpers.cr and inspect how Lucky::Paginator::BackendHelpers depends on context and params when included outside an action. The issue leaves two designs open: a compile-time restriction with the pagination formula, or support for supplied pagination methods in GraphQL::Object. Done requires choosing and implementing one behavior with appropriate coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal, graphql
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100