chore: make connection paging more like standard

This commit is contained in:
Jon Lundy
2022-10-25 20:15:57 -06:00
parent 7ae2a8ad25
commit 9dd9443bc9
14 changed files with 350 additions and 41 deletions

View File

@@ -6,8 +6,9 @@ type Connection @goModel(model: "github.com/sour-is/ev/pkg/gql.Connection") {
edges: [Edge!]!
}
input PageInput @goModel(model: "github.com/sour-is/ev/pkg/gql.PageInput") {
idx: Int = 0
count: Int = 30
after: Int = 0
before: Int
count: Int = 30
}
type PageInfo @goModel(model: "github.com/sour-is/ev/pkg/gql.PageInfo") {
next: Boolean!

View File

@@ -38,19 +38,30 @@ type PageInfo struct {
}
type PageInput struct {
Idx *int64 `json:"idx"`
Count *int64 `json:"count"`
After *int64 `json:"after"`
Before *int64 `json:"before"`
Count *int64 `json:"count"`
}
func (p *PageInput) GetIdx(v int64) int64 {
if p == nil || p.Idx == nil {
return v
if p == nil {
// pass
} else if p.Before != nil {
return (*p.Before)
} else if p.After != nil {
return *p.After
}
return *p.Idx
return v
}
func (p *PageInput) GetCount(v int64) int64 {
if p == nil || p.Count == nil {
return v
} else if p.Before != nil {
return -(*p.Count)
} else if p.After != nil {
return *p.Count
}
return *p.Count
}