diff options
Diffstat (limited to 'graphql/connections')
-rw-r--r-- | graphql/connections/connection_template.go | 16 | ||||
-rw-r--r-- | graphql/connections/gen_bug.go | 16 | ||||
-rw-r--r-- | graphql/connections/gen_comment.go | 18 | ||||
-rw-r--r-- | graphql/connections/gen_operation.go | 18 |
4 files changed, 52 insertions, 16 deletions
diff --git a/graphql/connections/connection_template.go b/graphql/connections/connection_template.go index 7f97c00b..a4608430 100644 --- a/graphql/connections/connection_template.go +++ b/graphql/connections/connection_template.go @@ -11,13 +11,19 @@ type EdgeType generic.Type type ConnectionType generic.Type type NodeTypeEdger func(value NodeType, offset int) Edge -type NodeTypeConMaker func(edges []EdgeType, info models.PageInfo, totalCount int) (ConnectionType, error) + +type NodeTypeConMaker func( + edges []EdgeType, + nodes []NodeType, + info models.PageInfo, + totalCount int) (ConnectionType, error) func NodeTypeCon(source []NodeType, edger NodeTypeEdger, conMaker NodeTypeConMaker, input models.ConnectionInput) (ConnectionType, error) { + var nodes []NodeType var edges []EdgeType var pageInfo models.PageInfo - emptyCon, _ := conMaker(edges, pageInfo, 0) + emptyCon, _ := conMaker(edges, nodes, pageInfo, 0) offset := 0 @@ -43,9 +49,11 @@ func NodeTypeCon(source []NodeType, edger NodeTypeEdger, conMaker NodeTypeConMak } edges = append(edges, edge.(EdgeType)) + nodes = append(nodes, value) } } else { edges = make([]EdgeType, len(source)) + nodes = source for i, value := range source { edges[i] = edger(value, i+offset).(EdgeType) @@ -60,6 +68,7 @@ func NodeTypeCon(source []NodeType, edger NodeTypeEdger, conMaker NodeTypeConMak if len(edges) > *input.First { // Slice result to be of length first by removing edges from the end edges = edges[:*input.First] + nodes = nodes[:*input.First] pageInfo.HasNextPage = true } } @@ -72,9 +81,10 @@ func NodeTypeCon(source []NodeType, edger NodeTypeEdger, conMaker NodeTypeConMak if len(edges) > *input.Last { // Slice result to be of length last by removing edges from the start edges = edges[len(edges)-*input.Last:] + nodes = nodes[len(nodes)-*input.Last:] pageInfo.HasPreviousPage = true } } - return conMaker(edges, pageInfo, len(source)) + return conMaker(edges, nodes, pageInfo, len(source)) } diff --git a/graphql/connections/gen_bug.go b/graphql/connections/gen_bug.go index 64458669..9224c696 100644 --- a/graphql/connections/gen_bug.go +++ b/graphql/connections/gen_bug.go @@ -11,13 +11,19 @@ import ( ) type StringEdger func(value string, offset int) Edge -type StringConMaker func(edges []LazyBugEdge, info models.PageInfo, totalCount int) (models.BugConnection, error) + +type StringConMaker func( + edges []LazyBugEdge, + nodes []string, + info models.PageInfo, + totalCount int) (models.BugConnection, error) func StringCon(source []string, edger StringEdger, conMaker StringConMaker, input models.ConnectionInput) (models.BugConnection, error) { + var nodes []string var edges []LazyBugEdge var pageInfo models.PageInfo - emptyCon, _ := conMaker(edges, pageInfo, 0) + emptyCon, _ := conMaker(edges, nodes, pageInfo, 0) offset := 0 @@ -43,9 +49,11 @@ func StringCon(source []string, edger StringEdger, conMaker StringConMaker, inpu } edges = append(edges, edge.(LazyBugEdge)) + nodes = append(nodes, value) } } else { edges = make([]LazyBugEdge, len(source)) + nodes = source for i, value := range source { edges[i] = edger(value, i+offset).(LazyBugEdge) @@ -60,6 +68,7 @@ func StringCon(source []string, edger StringEdger, conMaker StringConMaker, inpu if len(edges) > *input.First { // Slice result to be of length first by removing edges from the end edges = edges[:*input.First] + nodes = nodes[:*input.First] pageInfo.HasNextPage = true } } @@ -72,9 +81,10 @@ func StringCon(source []string, edger StringEdger, conMaker StringConMaker, inpu if len(edges) > *input.Last { // Slice result to be of length last by removing edges from the start edges = edges[len(edges)-*input.Last:] + nodes = nodes[len(nodes)-*input.Last:] pageInfo.HasPreviousPage = true } } - return conMaker(edges, pageInfo, len(source)) + return conMaker(edges, nodes, pageInfo, len(source)) } diff --git a/graphql/connections/gen_comment.go b/graphql/connections/gen_comment.go index dfcce42a..0253e831 100644 --- a/graphql/connections/gen_comment.go +++ b/graphql/connections/gen_comment.go @@ -12,13 +12,19 @@ import ( ) type BugCommentEdger func(value bug.Comment, offset int) Edge -type BugCommentConMaker func(edges []models.CommentEdge, info models.PageInfo, totalCount int) models.CommentConnection + +type BugCommentConMaker func( + edges []models.CommentEdge, + nodes []bug.Comment, + info models.PageInfo, + totalCount int) (models.CommentConnection, error) func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugCommentConMaker, input models.ConnectionInput) (models.CommentConnection, error) { + var nodes []bug.Comment var edges []models.CommentEdge var pageInfo models.PageInfo - emptyCon := conMaker(edges, pageInfo, 0) + emptyCon, _ := conMaker(edges, nodes, pageInfo, 0) offset := 0 @@ -44,9 +50,11 @@ func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugComm } edges = append(edges, edge.(models.CommentEdge)) + nodes = append(nodes, value) } } else { edges = make([]models.CommentEdge, len(source)) + nodes = source for i, value := range source { edges[i] = edger(value, i+offset).(models.CommentEdge) @@ -61,6 +69,7 @@ func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugComm if len(edges) > *input.First { // Slice result to be of length first by removing edges from the end edges = edges[:*input.First] + nodes = nodes[:*input.First] pageInfo.HasNextPage = true } } @@ -73,11 +82,10 @@ func BugCommentCon(source []bug.Comment, edger BugCommentEdger, conMaker BugComm if len(edges) > *input.Last { // Slice result to be of length last by removing edges from the start edges = edges[len(edges)-*input.Last:] + nodes = nodes[len(nodes)-*input.Last:] pageInfo.HasPreviousPage = true } } - con := conMaker(edges, pageInfo, len(source)) - - return con, nil + return conMaker(edges, nodes, pageInfo, len(source)) } diff --git a/graphql/connections/gen_operation.go b/graphql/connections/gen_operation.go index 32cee97a..26936dfe 100644 --- a/graphql/connections/gen_operation.go +++ b/graphql/connections/gen_operation.go @@ -12,13 +12,19 @@ import ( ) type BugOperationEdger func(value bug.Operation, offset int) Edge -type BugOperationConMaker func(edges []models.OperationEdge, info models.PageInfo, totalCount int) models.OperationConnection + +type BugOperationConMaker func( + edges []models.OperationEdge, + nodes []bug.Operation, + info models.PageInfo, + totalCount int) (models.OperationConnection, error) func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker BugOperationConMaker, input models.ConnectionInput) (models.OperationConnection, error) { + var nodes []bug.Operation var edges []models.OperationEdge var pageInfo models.PageInfo - emptyCon := conMaker(edges, pageInfo, 0) + emptyCon, _ := conMaker(edges, nodes, pageInfo, 0) offset := 0 @@ -44,9 +50,11 @@ func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker B } edges = append(edges, edge.(models.OperationEdge)) + nodes = append(nodes, value) } } else { edges = make([]models.OperationEdge, len(source)) + nodes = source for i, value := range source { edges[i] = edger(value, i+offset).(models.OperationEdge) @@ -61,6 +69,7 @@ func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker B if len(edges) > *input.First { // Slice result to be of length first by removing edges from the end edges = edges[:*input.First] + nodes = nodes[:*input.First] pageInfo.HasNextPage = true } } @@ -73,11 +82,10 @@ func BugOperationCon(source []bug.Operation, edger BugOperationEdger, conMaker B if len(edges) > *input.Last { // Slice result to be of length last by removing edges from the start edges = edges[len(edges)-*input.Last:] + nodes = nodes[len(nodes)-*input.Last:] pageInfo.HasPreviousPage = true } } - con := conMaker(edges, pageInfo, len(source)) - - return con, nil + return conMaker(edges, nodes, pageInfo, len(source)) } |