aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/connections
diff options
context:
space:
mode:
Diffstat (limited to 'graphql/connections')
-rw-r--r--graphql/connections/connection_template.go10
-rw-r--r--graphql/connections/connections.go5
-rw-r--r--graphql/connections/gen_bug.go4
-rw-r--r--graphql/connections/gen_comment.go4
-rw-r--r--graphql/connections/gen_operation.go4
-rw-r--r--graphql/connections/lazy_bug.go2
6 files changed, 27 insertions, 2 deletions
diff --git a/graphql/connections/connection_template.go b/graphql/connections/connection_template.go
index a4608430..511f48d3 100644
--- a/graphql/connections/connection_template.go
+++ b/graphql/connections/connection_template.go
@@ -2,22 +2,32 @@ package connections
import (
"fmt"
+
"github.com/MichaelMure/git-bug/graphql/models"
"github.com/cheekybits/genny/generic"
)
+// 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
+// NodeTypeEdger define a function that take a NodeType and an offset and
+// create an Edge.
type NodeTypeEdger func(value NodeType, offset int) Edge
+// NodeTypeConMaker define a function that create a ConnectionType
type NodeTypeConMaker func(
edges []EdgeType,
nodes []NodeType,
info models.PageInfo,
totalCount int) (ConnectionType, error)
+// NodeTypeCon will paginate a source according to the input of a relay connection
func NodeTypeCon(source []NodeType, edger NodeTypeEdger, conMaker NodeTypeConMaker, input models.ConnectionInput) (ConnectionType, error) {
var nodes []NodeType
var edges []EdgeType
diff --git a/graphql/connections/connections.go b/graphql/connections/connections.go
index 84dc3750..8b905fab 100644
--- a/graphql/connections/connections.go
+++ b/graphql/connections/connections.go
@@ -13,17 +13,18 @@ import (
const cursorPrefix = "cursor:"
+// Edge define the contract for an edge in a relay connection
type Edge interface {
GetCursor() string
}
-// Creates the cursor string from an offset
+// OffsetToCursor create the cursor string from an offset
func OffsetToCursor(offset int) string {
str := fmt.Sprintf("%v%v", cursorPrefix, offset)
return base64.StdEncoding.EncodeToString([]byte(str))
}
-// Re-derives the offset from the cursor string.
+// CursorToOffset re-derives the offset from the cursor string.
func CursorToOffset(cursor string) (int, error) {
str := ""
b, err := base64.StdEncoding.DecodeString(cursor)
diff --git a/graphql/connections/gen_bug.go b/graphql/connections/gen_bug.go
index 9224c696..e9654986 100644
--- a/graphql/connections/gen_bug.go
+++ b/graphql/connections/gen_bug.go
@@ -10,14 +10,18 @@ import (
"github.com/MichaelMure/git-bug/graphql/models"
)
+// StringEdger define a function that take a string and an offset and
+// create an Edge.
type StringEdger func(value string, offset int) Edge
+// StringConMaker define a function that create a models.BugConnection
type StringConMaker func(
edges []LazyBugEdge,
nodes []string,
info models.PageInfo,
totalCount int) (models.BugConnection, error)
+// StringCon will paginate a source according to the input of a relay connection
func StringCon(source []string, edger StringEdger, conMaker StringConMaker, input models.ConnectionInput) (models.BugConnection, error) {
var nodes []string
var edges []LazyBugEdge
diff --git a/graphql/connections/gen_comment.go b/graphql/connections/gen_comment.go
index 0253e831..57fad3af 100644
--- a/graphql/connections/gen_comment.go
+++ b/graphql/connections/gen_comment.go
@@ -11,14 +11,18 @@ import (
"github.com/MichaelMure/git-bug/graphql/models"
)
+// BugCommentEdger define a function that take a bug.Comment and an offset and
+// create an Edge.
type BugCommentEdger func(value bug.Comment, offset int) Edge
+// BugCommentConMaker define a function that create a models.CommentConnection
type BugCommentConMaker func(
edges []models.CommentEdge,
nodes []bug.Comment,
info models.PageInfo,
totalCount int) (models.CommentConnection, error)
+// BugCommentCon will paginate a source according to the input of a relay connection
func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugCommentConMaker, input models.ConnectionInput) (models.CommentConnection, error) {
var nodes []bug.Comment
var edges []models.CommentEdge
diff --git a/graphql/connections/gen_operation.go b/graphql/connections/gen_operation.go
index 26936dfe..570c67cd 100644
--- a/graphql/connections/gen_operation.go
+++ b/graphql/connections/gen_operation.go
@@ -11,14 +11,18 @@ import (
"github.com/MichaelMure/git-bug/graphql/models"
)
+// BugOperationEdger define a function that take a bug.Operation and an offset and
+// create an Edge.
type BugOperationEdger func(value bug.Operation, offset int) Edge
+// BugOperationConMaker define a function that create a models.OperationConnection
type BugOperationConMaker func(
edges []models.OperationEdge,
nodes []bug.Operation,
info models.PageInfo,
totalCount int) (models.OperationConnection, error)
+// BugOperationCon will paginate a source according to the input of a relay connection
func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker BugOperationConMaker, input models.ConnectionInput) (models.OperationConnection, error) {
var nodes []bug.Operation
var edges []models.OperationEdge
diff --git a/graphql/connections/lazy_bug.go b/graphql/connections/lazy_bug.go
index 35dcb687..24eda0b6 100644
--- a/graphql/connections/lazy_bug.go
+++ b/graphql/connections/lazy_bug.go
@@ -1,10 +1,12 @@
package connections
+// LazyBugEdge is a special relay edge used to implement a lazy loading connection
type LazyBugEdge struct {
Id string
Cursor string
}
+// GetCursor return the cursor of a LazyBugEdge
func (lbe LazyBugEdge) GetCursor() string {
return lbe.Cursor
}