Skip to content

Commit

Permalink
Limit number of items in a page
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Aug 7, 2018
1 parent 085e366 commit 78de763
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def email(id:)
description "All emails. Most recent emails come first."
end

# TODO: Limit number of items in a page
# TODO: Switch over to more relay-like pagination
def emails(app_id: nil, status: nil, limit: 10, offset: 0)
paginate(limit, offset) do
Expand All @@ -45,7 +44,6 @@ def emails(app_id: nil, status: nil, limit: 10, offset: 0)
description "All apps"
end

# TODO: Limit number of items in a page
# TODO: Switch over to more relay-like pagination
def apps(limit: 10, offset: 0)
paginate(limit, offset) do
Expand Down Expand Up @@ -73,6 +71,9 @@ def viewer

def paginate(limit, offset, &block)
r = yield block
{ nodes: r.offset(offset).limit(limit), total_count: r.count }
{ nodes: r.offset(offset).limit([limit, MAX_LIMIT].min), total_count: r.count }
end

# Limit can never be bigger than 50
MAX_LIMIT = 50
end

0 comments on commit 78de763

Please sign in to comment.