From 99f88913f642772b41f1c892a796e605e820a00c Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 7 May 2020 11:29:01 -0400 Subject: [PATCH] API: Implement count for filters -> cursor --- api/graph/model/cursor.go | 18 +++++++++++++++++- api/graph/schema.resolvers.go | 6 +++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/api/graph/model/cursor.go b/api/graph/model/cursor.go index d6108b1..69b8f54 100644 --- a/api/graph/model/cursor.go +++ b/api/graph/model/cursor.go @@ -43,8 +43,24 @@ func (cur Cursor) MarshalGQL(w io.Writer) { w.Write([]byte("\"")) } +func derefOrInt(i *int, d int) int { + if i != nil { + return *i + } + return d +} + func NewCursor(filter *Filter) *Cursor { - // TODO: Apply filter + if filter != nil { + return &Cursor{ + Next: "", + + Count: derefOrInt(filter.Count, 25), + // TODO: + OrderBy: "", + Search: "", + } + } return &Cursor{ Count: 25, Next: "", diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index 9c4d271..742f2aa 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -185,14 +185,14 @@ func (r *userResolver) Repositories(ctx context.Context, obj *model.User, cursor repos = append(repos, &repo) } - if len(repos) > 25 { + if len(repos) > cursor.Count { cursor = &model.Cursor{ - Count: 25, + Count: cursor.Count, Next: strconv.Itoa(repos[len(repos)-1].ID), OrderBy: `id DESC`, Search: "", } - repos = repos[:25] + repos = repos[:cursor.Count] } else { cursor = nil } -- 2.38.4