aboutsummaryrefslogtreecommitdiffstats
path: root/api/graphql/connections
diff options
context:
space:
mode:
Diffstat (limited to 'api/graphql/connections')
-rw-r--r--api/graphql/connections/connection_template.go122
-rw-r--r--api/graphql/connections/connections.go116
-rw-r--r--api/graphql/connections/gen_comment.go113
-rw-r--r--api/graphql/connections/gen_identity.go112
-rw-r--r--api/graphql/connections/gen_label.go113
-rw-r--r--api/graphql/connections/gen_lazy_bug.go113
-rw-r--r--api/graphql/connections/gen_lazy_identity.go113
-rw-r--r--api/graphql/connections/gen_operation.go113
-rw-r--r--api/graphql/connections/gen_timeline.go113
9 files changed, 108 insertions, 920 deletions
diff --git a/api/graphql/connections/connection_template.go b/api/graphql/connections/connection_template.go
deleted file mode 100644
index b97d1ece..00000000
--- a/api/graphql/connections/connection_template.go
+++ /dev/null
@@ -1,122 +0,0 @@
-package connections
-
-import (
- "fmt"
-
- "github.com/cheekybits/genny/generic"
-
- "github.com/git-bug/git-bug/api/graphql/models"
-)
-
-// Name define the name of the connection
-type Name generic.Type
-
-// NodeType define the node type handled by this relay connection
-type NodeType generic.Type
-
-// EdgeType define the edge type handled by this relay connection
-type EdgeType generic.Type
-
-// ConnectionType define the connection type handled by this relay connection
-type ConnectionType generic.Type
-
-// NameEdgeMaker define a function that take a NodeType and an offset and
-// create an Edge.
-type NameEdgeMaker func(value NodeType, offset int) Edge
-
-// NameConMaker define a function that create a ConnectionType
-type NameConMaker func(
- edges []*EdgeType,
- nodes []NodeType,
- info *models.PageInfo,
- totalCount int) (*ConnectionType, error)
-
-// NameCon will paginate a source according to the input of a relay connection
-func NameCon(source []NodeType, edgeMaker NameEdgeMaker, conMaker NameConMaker, input models.ConnectionInput) (*ConnectionType, error) {
- var nodes []NodeType
- var edges []*EdgeType
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(EdgeType)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*EdgeType, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(EdgeType)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}
diff --git a/api/graphql/connections/connections.go b/api/graphql/connections/connections.go
index bfdf8909..1ac2294f 100644
--- a/api/graphql/connections/connections.go
+++ b/api/graphql/connections/connections.go
@@ -1,11 +1,3 @@
-//go:generate genny -in=connection_template.go -out=gen_lazy_bug.go gen "Name=LazyBug NodeType=entity.Id EdgeType=LazyBugEdge ConnectionType=models.BugConnection"
-//go:generate genny -in=connection_template.go -out=gen_lazy_identity.go gen "Name=LazyIdentity NodeType=entity.Id EdgeType=LazyIdentityEdge ConnectionType=models.IdentityConnection"
-//go:generate genny -in=connection_template.go -out=gen_identity.go gen "Name=Identity NodeType=models.IdentityWrapper EdgeType=models.IdentityEdge ConnectionType=models.IdentityConnection"
-//go:generate genny -in=connection_template.go -out=gen_operation.go gen "Name=Operation NodeType=dag.Operation EdgeType=models.OperationEdge ConnectionType=models.OperationConnection"
-//go:generate genny -in=connection_template.go -out=gen_comment.go gen "Name=Comment NodeType=bug.Comment EdgeType=models.CommentEdge ConnectionType=models.CommentConnection"
-//go:generate genny -in=connection_template.go -out=gen_timeline.go gen "Name=TimelineItem NodeType=bug.TimelineItem EdgeType=models.TimelineItemEdge ConnectionType=models.TimelineItemConnection"
-//go:generate genny -in=connection_template.go -out=gen_label.go gen "Name=Label NodeType=bug.Label EdgeType=models.LabelEdge ConnectionType=models.LabelConnection"
-
// Package connections implement a generic GraphQL relay connection
package connections
@@ -14,6 +6,8 @@ import (
"fmt"
"strconv"
"strings"
+
+ "github.com/git-bug/git-bug/api/graphql/models"
)
const cursorPrefix = "cursor:"
@@ -43,3 +37,109 @@ func CursorToOffset(cursor string) (int, error) {
}
return offset, nil
}
+
+// EdgeMaker defines a function that takes a NodeType and an offset and
+// create an Edge.
+type EdgeMaker[NodeType any] func(value NodeType, offset int) Edge
+
+// ConMaker defines a function that creates a ConnectionType
+type ConMaker[NodeType any, EdgeType Edge, ConType any] func(
+ edges []*EdgeType,
+ nodes []NodeType,
+ info *models.PageInfo,
+ totalCount int) (*ConType, error)
+
+// Connection will paginate a source according to the input of a relay connection
+func Connection[NodeType any, EdgeType Edge, ConType any](
+ source []NodeType,
+ edgeMaker EdgeMaker[NodeType],
+ conMaker ConMaker[NodeType, EdgeType, ConType],
+ input models.ConnectionInput) (*ConType, error) {
+
+ var nodes []NodeType
+ var edges []*EdgeType
+ var cursors []string
+ var pageInfo = &models.PageInfo{}
+ var totalCount = len(source)
+
+ emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
+
+ offset := 0
+
+ if input.After != nil {
+ for i, value := range source {
+ edge := edgeMaker(value, i)
+ if edge.GetCursor() == *input.After {
+ // remove all previous element including the "after" one
+ source = source[i+1:]
+ offset = i + 1
+ pageInfo.HasPreviousPage = true
+ break
+ }
+ }
+ }
+
+ if input.Before != nil {
+ for i, value := range source {
+ edge := edgeMaker(value, i+offset)
+
+ if edge.GetCursor() == *input.Before {
+ // remove all after element including the "before" one
+ pageInfo.HasNextPage = true
+ break
+ }
+
+ e := edge.(EdgeType)
+ edges = append(edges, &e)
+ cursors = append(cursors, edge.GetCursor())
+ nodes = append(nodes, value)
+ }
+ } else {
+ edges = make([]*EdgeType, len(source))
+ cursors = make([]string, len(source))
+ nodes = source
+
+ for i, value := range source {
+ edge := edgeMaker(value, i+offset)
+ e := edge.(EdgeType)
+ edges[i] = &e
+ cursors[i] = edge.GetCursor()
+ }
+ }
+
+ if input.First != nil {
+ if *input.First < 0 {
+ return emptyCon, fmt.Errorf("first less than zero")
+ }
+
+ if len(edges) > *input.First {
+ // Slice result to be of length first by removing edges from the end
+ edges = edges[:*input.First]
+ cursors = cursors[:*input.First]
+ nodes = nodes[:*input.First]
+ pageInfo.HasNextPage = true
+ }
+ }
+
+ if input.Last != nil {
+ if *input.Last < 0 {
+ return emptyCon, fmt.Errorf("last less than zero")
+ }
+
+ if len(edges) > *input.Last {
+ // Slice result to be of length last by removing edges from the start
+ edges = edges[len(edges)-*input.Last:]
+ cursors = cursors[len(cursors)-*input.Last:]
+ nodes = nodes[len(nodes)-*input.Last:]
+ pageInfo.HasPreviousPage = true
+ }
+ }
+
+ // Fill up pageInfo cursors
+ if len(cursors) > 0 {
+ pageInfo.StartCursor = cursors[0]
+ pageInfo.EndCursor = cursors[len(cursors)-1]
+ }
+
+ return conMaker(edges, nodes, pageInfo, totalCount)
+}
diff --git a/api/graphql/connections/gen_comment.go b/api/graphql/connections/gen_comment.go
deleted file mode 100644
index 1994aced..00000000
--- a/api/graphql/connections/gen_comment.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// This file was automatically generated by genny.
-// Any changes will be lost if this file is regenerated.
-// see https://github.com/cheekybits/genny
-
-package connections
-
-import (
- "fmt"
-
- "github.com/git-bug/git-bug/api/graphql/models"
- "github.com/git-bug/git-bug/entities/bug"
-)
-
-// BugCommentEdgeMaker define a function that take a bug.Comment and an offset and
-// create an Edge.
-type CommentEdgeMaker func(value bug.Comment, offset int) Edge
-
-// CommentConMaker define a function that create a models.CommentConnection
-type CommentConMaker func(
- edges []*models.CommentEdge,
- nodes []bug.Comment,
- info *models.PageInfo,
- totalCount int) (*models.CommentConnection, error)
-
-// CommentCon will paginate a source according to the input of a relay connection
-func CommentCon(source []bug.Comment, edgeMaker CommentEdgeMaker, conMaker CommentConMaker, input models.ConnectionInput) (*models.CommentConnection, error) {
- var nodes []bug.Comment
- var edges []*models.CommentEdge
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(models.CommentEdge)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*models.CommentEdge, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(models.CommentEdge)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}
diff --git a/api/graphql/connections/gen_identity.go b/api/graphql/connections/gen_identity.go
deleted file mode 100644
index cdd9c077..00000000
--- a/api/graphql/connections/gen_identity.go
+++ /dev/null
@@ -1,112 +0,0 @@
-// This file was automatically generated by genny.
-// Any changes will be lost if this file is regenerated.
-// see https://github.com/cheekybits/genny
-
-package connections
-
-import (
- "fmt"
-
- "github.com/git-bug/git-bug/api/graphql/models"
-)
-
-// IdentityEdgeMaker define a function that take a models.IdentityWrapper and an offset and
-// create an Edge.
-type IdentityEdgeMaker func(value models.IdentityWrapper, offset int) Edge
-
-// IdentityConMaker define a function that create a models.IdentityConnection
-type IdentityConMaker func(
- edges []*models.IdentityEdge,
- nodes []models.IdentityWrapper,
- info *models.PageInfo,
- totalCount int) (*models.IdentityConnection, error)
-
-// IdentityCon will paginate a source according to the input of a relay connection
-func IdentityCon(source []models.IdentityWrapper, edgeMaker IdentityEdgeMaker, conMaker IdentityConMaker, input models.ConnectionInput) (*models.IdentityConnection, error) {
- var nodes []models.IdentityWrapper
- var edges []*models.IdentityEdge
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(models.IdentityEdge)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*models.IdentityEdge, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(models.IdentityEdge)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}
diff --git a/api/graphql/connections/gen_label.go b/api/graphql/connections/gen_label.go
deleted file mode 100644
index 238305b4..00000000
--- a/api/graphql/connections/gen_label.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// This file was automatically generated by genny.
-// Any changes will be lost if this file is regenerated.
-// see https://github.com/cheekybits/genny
-
-package connections
-
-import (
- "fmt"
-
- "github.com/git-bug/git-bug/api/graphql/models"
- "github.com/git-bug/git-bug/entities/bug"
-)
-
-// BugLabelEdgeMaker define a function that take a bug.Label and an offset and
-// create an Edge.
-type LabelEdgeMaker func(value bug.Label, offset int) Edge
-
-// LabelConMaker define a function that create a models.LabelConnection
-type LabelConMaker func(
- edges []*models.LabelEdge,
- nodes []bug.Label,
- info *models.PageInfo,
- totalCount int) (*models.LabelConnection, error)
-
-// LabelCon will paginate a source according to the input of a relay connection
-func LabelCon(source []bug.Label, edgeMaker LabelEdgeMaker, conMaker LabelConMaker, input models.ConnectionInput) (*models.LabelConnection, error) {
- var nodes []bug.Label
- var edges []*models.LabelEdge
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(models.LabelEdge)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*models.LabelEdge, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(models.LabelEdge)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}
diff --git a/api/graphql/connections/gen_lazy_bug.go b/api/graphql/connections/gen_lazy_bug.go
deleted file mode 100644
index 5a7af08f..00000000
--- a/api/graphql/connections/gen_lazy_bug.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// This file was automatically generated by genny.
-// Any changes will be lost if this file is regenerated.
-// see https://github.com/cheekybits/genny
-
-package connections
-
-import (
- "fmt"
-
- "github.com/git-bug/git-bug/api/graphql/models"
- "github.com/git-bug/git-bug/entity"
-)
-
-// LazyBugEdgeMaker define a function that take a entity.Id and an offset and
-// create an Edge.
-type LazyBugEdgeMaker func(value entity.Id, offset int) Edge
-
-// LazyBugConMaker define a function that create a models.BugConnection
-type LazyBugConMaker func(
- edges []*LazyBugEdge,
- nodes []entity.Id,
- info *models.PageInfo,
- totalCount int) (*models.BugConnection, error)
-
-// LazyBugCon will paginate a source according to the input of a relay connection
-func LazyBugCon(source []entity.Id, edgeMaker LazyBugEdgeMaker, conMaker LazyBugConMaker, input models.ConnectionInput) (*models.BugConnection, error) {
- var nodes []entity.Id
- var edges []*LazyBugEdge
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(LazyBugEdge)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*LazyBugEdge, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(LazyBugEdge)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}
diff --git a/api/graphql/connections/gen_lazy_identity.go b/api/graphql/connections/gen_lazy_identity.go
deleted file mode 100644
index acb1d048..00000000
--- a/api/graphql/connections/gen_lazy_identity.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// This file was automatically generated by genny.
-// Any changes will be lost if this file is regenerated.
-// see https://github.com/cheekybits/genny
-
-package connections
-
-import (
- "fmt"
-
- "github.com/git-bug/git-bug/api/graphql/models"
- "github.com/git-bug/git-bug/entity"
-)
-
-// LazyIdentityEdgeMaker define a function that take a entity.Id and an offset and
-// create an Edge.
-type LazyIdentityEdgeMaker func(value entity.Id, offset int) Edge
-
-// LazyIdentityConMaker define a function that create a models.IdentityConnection
-type LazyIdentityConMaker func(
- edges []*LazyIdentityEdge,
- nodes []entity.Id,
- info *models.PageInfo,
- totalCount int) (*models.IdentityConnection, error)
-
-// LazyIdentityCon will paginate a source according to the input of a relay connection
-func LazyIdentityCon(source []entity.Id, edgeMaker LazyIdentityEdgeMaker, conMaker LazyIdentityConMaker, input models.ConnectionInput) (*models.IdentityConnection, error) {
- var nodes []entity.Id
- var edges []*LazyIdentityEdge
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(LazyIdentityEdge)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*LazyIdentityEdge, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(LazyIdentityEdge)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}
diff --git a/api/graphql/connections/gen_operation.go b/api/graphql/connections/gen_operation.go
deleted file mode 100644
index bfdf3491..00000000
--- a/api/graphql/connections/gen_operation.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// This file was automatically generated by genny.
-// Any changes will be lost if this file is regenerated.
-// see https://github.com/cheekybits/genny
-
-package connections
-
-import (
- "fmt"
-
- "github.com/git-bug/git-bug/api/graphql/models"
- "github.com/git-bug/git-bug/entity/dag"
-)
-
-// DagOperationEdgeMaker define a function that take a dag.Operation and an offset and
-// create an Edge.
-type OperationEdgeMaker func(value dag.Operation, offset int) Edge
-
-// OperationConMaker define a function that create a models.OperationConnection
-type OperationConMaker func(
- edges []*models.OperationEdge,
- nodes []dag.Operation,
- info *models.PageInfo,
- totalCount int) (*models.OperationConnection, error)
-
-// OperationCon will paginate a source according to the input of a relay connection
-func OperationCon(source []dag.Operation, edgeMaker OperationEdgeMaker, conMaker OperationConMaker, input models.ConnectionInput) (*models.OperationConnection, error) {
- var nodes []dag.Operation
- var edges []*models.OperationEdge
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(models.OperationEdge)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*models.OperationEdge, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(models.OperationEdge)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}
diff --git a/api/graphql/connections/gen_timeline.go b/api/graphql/connections/gen_timeline.go
deleted file mode 100644
index ea24f44c..00000000
--- a/api/graphql/connections/gen_timeline.go
+++ /dev/null
@@ -1,113 +0,0 @@
-// This file was automatically generated by genny.
-// Any changes will be lost if this file is regenerated.
-// see https://github.com/cheekybits/genny
-
-package connections
-
-import (
- "fmt"
-
- "github.com/git-bug/git-bug/api/graphql/models"
- "github.com/git-bug/git-bug/entities/bug"
-)
-
-// BugTimelineItemEdgeMaker define a function that take a bug.TimelineItem and an offset and
-// create an Edge.
-type TimelineItemEdgeMaker func(value bug.TimelineItem, offset int) Edge
-
-// TimelineItemConMaker define a function that create a models.TimelineItemConnection
-type TimelineItemConMaker func(
- edges []*models.TimelineItemEdge,
- nodes []bug.TimelineItem,
- info *models.PageInfo,
- totalCount int) (*models.TimelineItemConnection, error)
-
-// TimelineItemCon will paginate a source according to the input of a relay connection
-func TimelineItemCon(source []bug.TimelineItem, edgeMaker TimelineItemEdgeMaker, conMaker TimelineItemConMaker, input models.ConnectionInput) (*models.TimelineItemConnection, error) {
- var nodes []bug.TimelineItem
- var edges []*models.TimelineItemEdge
- var cursors []string
- var pageInfo = &models.PageInfo{}
- var totalCount = len(source)
-
- emptyCon, _ := conMaker(edges, nodes, pageInfo, 0)
-
- offset := 0
-
- if input.After != nil {
- for i, value := range source {
- edge := edgeMaker(value, i)
- if edge.GetCursor() == *input.After {
- // remove all previous element including the "after" one
- source = source[i+1:]
- offset = i + 1
- pageInfo.HasPreviousPage = true
- break
- }
- }
- }
-
- if input.Before != nil {
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
-
- if edge.GetCursor() == *input.Before {
- // remove all after element including the "before" one
- pageInfo.HasNextPage = true
- break
- }
-
- e := edge.(models.TimelineItemEdge)
- edges = append(edges, &e)
- cursors = append(cursors, edge.GetCursor())
- nodes = append(nodes, value)
- }
- } else {
- edges = make([]*models.TimelineItemEdge, len(source))
- cursors = make([]string, len(source))
- nodes = source
-
- for i, value := range source {
- edge := edgeMaker(value, i+offset)
- e := edge.(models.TimelineItemEdge)
- edges[i] = &e
- cursors[i] = edge.GetCursor()
- }
- }
-
- if input.First != nil {
- if *input.First < 0 {
- return emptyCon, fmt.Errorf("first less than zero")
- }
-
- if len(edges) > *input.First {
- // Slice result to be of length first by removing edges from the end
- edges = edges[:*input.First]
- cursors = cursors[:*input.First]
- nodes = nodes[:*input.First]
- pageInfo.HasNextPage = true
- }
- }
-
- if input.Last != nil {
- if *input.Last < 0 {
- return emptyCon, fmt.Errorf("last less than zero")
- }
-
- if len(edges) > *input.Last {
- // Slice result to be of length last by removing edges from the start
- edges = edges[len(edges)-*input.Last:]
- cursors = cursors[len(cursors)-*input.Last:]
- nodes = nodes[len(nodes)-*input.Last:]
- pageInfo.HasPreviousPage = true
- }
- }
-
- // Fill up pageInfo cursors
- if len(cursors) > 0 {
- pageInfo.StartCursor = cursors[0]
- pageInfo.EndCursor = cursors[len(cursors)-1]
- }
-
- return conMaker(edges, nodes, pageInfo, totalCount)
-}