aboutsummaryrefslogtreecommitdiffstats
path: root/graphql
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-01 19:24:19 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-01 19:24:19 +0200
commit15f282421941b90e1f62912cf68b7556a8ce7b33 (patch)
tree085c77b22313f1bf4650901de3197f4f200aba28 /graphql
parent5830dd88414608b5fc6f5f2b44293b079bce2829 (diff)
downloadgit-bug-15f282421941b90e1f62912cf68b7556a8ce7b33.tar.gz
graphql: simplify the requests with helpers
Diffstat (limited to 'graphql')
-rw-r--r--graphql/connections/connection_template.go16
-rw-r--r--graphql/connections/gen_bug.go16
-rw-r--r--graphql/connections/gen_comment.go18
-rw-r--r--graphql/connections/gen_operation.go18
-rw-r--r--graphql/gqlgen.yml2
-rw-r--r--graphql/graph/gen_graph.go388
-rw-r--r--graphql/models/gen_models.go20
-rw-r--r--graphql/models/models.go7
-rw-r--r--graphql/resolvers/bug.go30
-rw-r--r--graphql/resolvers/repo.go20
-rw-r--r--graphql/schema.graphql60
11 files changed, 415 insertions, 180 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))
}
diff --git a/graphql/gqlgen.yml b/graphql/gqlgen.yml
index c4f395ab..51c53b62 100644
--- a/graphql/gqlgen.yml
+++ b/graphql/gqlgen.yml
@@ -17,6 +17,8 @@ models:
model: github.com/MichaelMure/git-bug/bug.Person
Label:
model: github.com/MichaelMure/git-bug/bug.Label
+ Operation:
+ model: github.com/MichaelMure/git-bug/bug.Operation
CreateOperation:
model: github.com/MichaelMure/git-bug/bug/operations.CreateOperation
SetTitleOperation:
diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go
index aa4fcc15..a5d36abe 100644
--- a/graphql/graph/gen_graph.go
+++ b/graphql/graph/gen_graph.go
@@ -33,8 +33,8 @@ type Resolvers interface {
Bug_status(ctx context.Context, obj *bug.Snapshot) (models.Status, error)
- Bug_comments(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.CommentConnection, error)
- Bug_operations(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.OperationConnection, error)
+ Bug_comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error)
+ Bug_operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error)
CreateOperation_date(ctx context.Context, obj *operations.CreateOperation) (time.Time, error)
@@ -45,7 +45,7 @@ type Resolvers interface {
Query_defaultRepository(ctx context.Context) (*models.Repository, error)
Query_repository(ctx context.Context, id string) (*models.Repository, error)
- Repository_allBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error)
+ Repository_allBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.BugConnection, error)
Repository_bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error)
SetStatusOperation_date(ctx context.Context, obj *operations.SetStatusOperation) (time.Time, error)
@@ -71,8 +71,8 @@ type AddCommentOperationResolver interface {
type BugResolver interface {
Status(ctx context.Context, obj *bug.Snapshot) (models.Status, error)
- Comments(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.CommentConnection, error)
- Operations(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.OperationConnection, error)
+ Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error)
+ Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error)
}
type CreateOperationResolver interface {
Date(ctx context.Context, obj *operations.CreateOperation) (time.Time, error)
@@ -88,7 +88,7 @@ type QueryResolver interface {
Repository(ctx context.Context, id string) (*models.Repository, error)
}
type RepositoryResolver interface {
- AllBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error)
+ AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.BugConnection, error)
Bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error)
}
type SetStatusOperationResolver interface {
@@ -111,12 +111,12 @@ func (s shortMapper) Bug_status(ctx context.Context, obj *bug.Snapshot) (models.
return s.r.Bug().Status(ctx, obj)
}
-func (s shortMapper) Bug_comments(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.CommentConnection, error) {
- return s.r.Bug().Comments(ctx, obj, input)
+func (s shortMapper) Bug_comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
+ return s.r.Bug().Comments(ctx, obj, after, before, first, last)
}
-func (s shortMapper) Bug_operations(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.OperationConnection, error) {
- return s.r.Bug().Operations(ctx, obj, input)
+func (s shortMapper) Bug_operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
+ return s.r.Bug().Operations(ctx, obj, after, before, first, last)
}
func (s shortMapper) CreateOperation_date(ctx context.Context, obj *operations.CreateOperation) (time.Time, error) {
@@ -139,8 +139,8 @@ func (s shortMapper) Query_repository(ctx context.Context, id string) (*models.R
return s.r.Query().Repository(ctx, id)
}
-func (s shortMapper) Repository_allBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error) {
- return s.r.Repository().AllBugs(ctx, obj, input)
+func (s shortMapper) Repository_allBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.BugConnection, error) {
+ return s.r.Repository().AllBugs(ctx, obj, after, before, first, last)
}
func (s shortMapper) Repository_bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error) {
@@ -408,16 +408,66 @@ func (ec *executionContext) _Bug_labels(ctx context.Context, field graphql.Colle
func (ec *executionContext) _Bug_comments(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler {
args := map[string]interface{}{}
- var arg0 models.ConnectionInput
- if tmp, ok := field.Args["input"]; ok {
+ var arg0 *string
+ if tmp, ok := field.Args["after"]; ok {
+ var err error
+ var ptr1 string
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalString(tmp)
+ arg0 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["after"] = arg0
+ var arg1 *string
+ if tmp, ok := field.Args["before"]; ok {
+ var err error
+ var ptr1 string
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalString(tmp)
+ arg1 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["before"] = arg1
+ var arg2 *int
+ if tmp, ok := field.Args["first"]; ok {
var err error
- arg0, err = UnmarshalConnectionInput(tmp)
+ var ptr1 int
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalInt(tmp)
+ arg2 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["first"] = arg2
+ var arg3 *int
+ if tmp, ok := field.Args["last"]; ok {
+ var err error
+ var ptr1 int
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalInt(tmp)
+ arg3 = &ptr1
+ }
+
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
}
- args["input"] = arg0
+ args["last"] = arg3
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Object: "Bug",
Args: args,
@@ -433,7 +483,7 @@ func (ec *executionContext) _Bug_comments(ctx context.Context, field graphql.Col
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
- return ec.resolvers.Bug_comments(ctx, obj, args["input"].(models.ConnectionInput))
+ return ec.resolvers.Bug_comments(ctx, obj, args["after"].(*string), args["before"].(*string), args["first"].(*int), args["last"].(*int))
})
if err != nil {
ec.Error(ctx, err)
@@ -449,16 +499,66 @@ func (ec *executionContext) _Bug_comments(ctx context.Context, field graphql.Col
func (ec *executionContext) _Bug_operations(ctx context.Context, field graphql.CollectedField, obj *bug.Snapshot) graphql.Marshaler {
args := map[string]interface{}{}
- var arg0 models.ConnectionInput
- if tmp, ok := field.Args["input"]; ok {
+ var arg0 *string
+ if tmp, ok := field.Args["after"]; ok {
+ var err error
+ var ptr1 string
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalString(tmp)
+ arg0 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["after"] = arg0
+ var arg1 *string
+ if tmp, ok := field.Args["before"]; ok {
+ var err error
+ var ptr1 string
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalString(tmp)
+ arg1 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["before"] = arg1
+ var arg2 *int
+ if tmp, ok := field.Args["first"]; ok {
var err error
- arg0, err = UnmarshalConnectionInput(tmp)
+ var ptr1 int
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalInt(tmp)
+ arg2 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["first"] = arg2
+ var arg3 *int
+ if tmp, ok := field.Args["last"]; ok {
+ var err error
+ var ptr1 int
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalInt(tmp)
+ arg3 = &ptr1
+ }
+
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
}
- args["input"] = arg0
+ args["last"] = arg3
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Object: "Bug",
Args: args,
@@ -474,7 +574,7 @@ func (ec *executionContext) _Bug_operations(ctx context.Context, field graphql.C
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
- return ec.resolvers.Bug_operations(ctx, obj, args["input"].(models.ConnectionInput))
+ return ec.resolvers.Bug_operations(ctx, obj, args["after"].(*string), args["before"].(*string), args["first"].(*int), args["last"].(*int))
})
if err != nil {
ec.Error(ctx, err)
@@ -503,6 +603,8 @@ func (ec *executionContext) _BugConnection(ctx context.Context, sel []query.Sele
out.Values[i] = graphql.MarshalString("BugConnection")
case "edges":
out.Values[i] = ec._BugConnection_edges(ctx, field, obj)
+ case "nodes":
+ out.Values[i] = ec._BugConnection_nodes(ctx, field, obj)
case "pageInfo":
out.Values[i] = ec._BugConnection_pageInfo(ctx, field, obj)
case "totalCount":
@@ -535,6 +637,26 @@ func (ec *executionContext) _BugConnection_edges(ctx context.Context, field grap
return arr1
}
+func (ec *executionContext) _BugConnection_nodes(ctx context.Context, field graphql.CollectedField, obj *models.BugConnection) graphql.Marshaler {
+ rctx := graphql.GetResolverContext(ctx)
+ rctx.Object = "BugConnection"
+ rctx.Args = nil
+ rctx.Field = field
+ rctx.PushField(field.Alias)
+ defer rctx.Pop()
+ res := obj.Nodes
+ arr1 := graphql.Array{}
+ for idx1 := range res {
+ arr1 = append(arr1, func() graphql.Marshaler {
+ rctx := graphql.GetResolverContext(ctx)
+ rctx.PushIndex(idx1)
+ defer rctx.Pop()
+ return ec._Bug(ctx, field.Selections, &res[idx1])
+ }())
+ }
+ return arr1
+}
+
func (ec *executionContext) _BugConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *models.BugConnection) graphql.Marshaler {
rctx := graphql.GetResolverContext(ctx)
rctx.Object = "BugConnection"
@@ -666,6 +788,8 @@ func (ec *executionContext) _CommentConnection(ctx context.Context, sel []query.
out.Values[i] = graphql.MarshalString("CommentConnection")
case "edges":
out.Values[i] = ec._CommentConnection_edges(ctx, field, obj)
+ case "nodes":
+ out.Values[i] = ec._CommentConnection_nodes(ctx, field, obj)
case "pageInfo":
out.Values[i] = ec._CommentConnection_pageInfo(ctx, field, obj)
case "totalCount":
@@ -698,6 +822,26 @@ func (ec *executionContext) _CommentConnection_edges(ctx context.Context, field
return arr1
}
+func (ec *executionContext) _CommentConnection_nodes(ctx context.Context, field graphql.CollectedField, obj *models.CommentConnection) graphql.Marshaler {
+ rctx := graphql.GetResolverContext(ctx)
+ rctx.Object = "CommentConnection"
+ rctx.Args = nil
+ rctx.Field = field
+ rctx.PushField(field.Alias)
+ defer rctx.Pop()
+ res := obj.Nodes
+ arr1 := graphql.Array{}
+ for idx1 := range res {
+ arr1 = append(arr1, func() graphql.Marshaler {
+ rctx := graphql.GetResolverContext(ctx)
+ rctx.PushIndex(idx1)
+ defer rctx.Pop()
+ return ec._Comment(ctx, field.Selections, &res[idx1])
+ }())
+ }
+ return arr1
+}
+
func (ec *executionContext) _CommentConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *models.CommentConnection) graphql.Marshaler {
rctx := graphql.GetResolverContext(ctx)
rctx.Object = "CommentConnection"
@@ -1068,6 +1212,8 @@ func (ec *executionContext) _OperationConnection(ctx context.Context, sel []quer
out.Values[i] = graphql.MarshalString("OperationConnection")
case "edges":
out.Values[i] = ec._OperationConnection_edges(ctx, field, obj)
+ case "nodes":
+ out.Values[i] = ec._OperationConnection_nodes(ctx, field, obj)
case "pageInfo":
out.Values[i] = ec._OperationConnection_pageInfo(ctx, field, obj)
case "totalCount":
@@ -1100,6 +1246,26 @@ func (ec *executionContext) _OperationConnection_edges(ctx context.Context, fiel
return arr1
}
+func (ec *executionContext) _OperationConnection_nodes(ctx context.Context, field graphql.CollectedField, obj *models.OperationConnection) graphql.Marshaler {
+ rctx := graphql.GetResolverContext(ctx)
+ rctx.Object = "OperationConnection"
+ rctx.Args = nil
+ rctx.Field = field
+ rctx.PushField(field.Alias)
+ defer rctx.Pop()
+ res := obj.Nodes
+ arr1 := graphql.Array{}
+ for idx1 := range res {
+ arr1 = append(arr1, func() graphql.Marshaler {
+ rctx := graphql.GetResolverContext(ctx)
+ rctx.PushIndex(idx1)
+ defer rctx.Pop()
+ return ec._Operation(ctx, field.Selections, &res[idx1])
+ }())
+ }
+ return arr1
+}
+
func (ec *executionContext) _OperationConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *models.OperationConnection) graphql.Marshaler {
rctx := graphql.GetResolverContext(ctx)
rctx.Object = "OperationConnection"
@@ -1439,16 +1605,66 @@ func (ec *executionContext) _Repository(ctx context.Context, sel []query.Selecti
func (ec *executionContext) _Repository_allBugs(ctx context.Context, field graphql.CollectedField, obj *models.Repository) graphql.Marshaler {
args := map[string]interface{}{}
- var arg0 models.ConnectionInput
- if tmp, ok := field.Args["input"]; ok {
+ var arg0 *string
+ if tmp, ok := field.Args["after"]; ok {
+ var err error
+ var ptr1 string
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalString(tmp)
+ arg0 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["after"] = arg0
+ var arg1 *string
+ if tmp, ok := field.Args["before"]; ok {
var err error
- arg0, err = UnmarshalConnectionInput(tmp)
+ var ptr1 string
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalString(tmp)
+ arg1 = &ptr1
+ }
+
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
}
- args["input"] = arg0
+ args["before"] = arg1
+ var arg2 *int
+ if tmp, ok := field.Args["first"]; ok {
+ var err error
+ var ptr1 int
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalInt(tmp)
+ arg2 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["first"] = arg2
+ var arg3 *int
+ if tmp, ok := field.Args["last"]; ok {
+ var err error
+ var ptr1 int
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalInt(tmp)
+ arg3 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["last"] = arg3
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Object: "Repository",
Args: args,
@@ -1464,7 +1680,7 @@ func (ec *executionContext) _Repository_allBugs(ctx context.Context, field graph
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(ctx context.Context) (interface{}, error) {
- return ec.resolvers.Repository_allBugs(ctx, obj, args["input"].(models.ConnectionInput))
+ return ec.resolvers.Repository_allBugs(ctx, obj, args["after"].(*string), args["before"].(*string), args["first"].(*int), args["last"].(*int))
})
if err != nil {
ec.Error(ctx, err)
@@ -2422,7 +2638,7 @@ func (ec *executionContext) _Authored(ctx context.Context, sel []query.Selection
}
}
-func (ec *executionContext) _Operation(ctx context.Context, sel []query.Selection, obj *models.Operation) graphql.Marshaler {
+func (ec *executionContext) _Operation(ctx context.Context, sel []query.Selection, obj *bug.Operation) graphql.Marshaler {
switch obj := (*obj).(type) {
case nil:
return graphql.Null
@@ -2451,62 +2667,6 @@ func (ec *executionContext) _Operation(ctx context.Context, sel []query.Selectio
}
}
-func UnmarshalConnectionInput(v interface{}) (models.ConnectionInput, error) {
- var it models.ConnectionInput
- var asMap = v.(map[string]interface{})
-
- for k, v := range asMap {
- switch k {
- case "after":
- var err error
- var ptr1 string
- if v != nil {
- ptr1, err = graphql.UnmarshalString(v)
- it.After = &ptr1
- }
-
- if err != nil {
- return it, err
- }
- case "before":
- var err error
- var ptr1 string
- if v != nil {
- ptr1, err = graphql.UnmarshalString(v)
- it.Before = &ptr1
- }
-
- if err != nil {
- return it, err
- }
- case "first":
- var err error
- var ptr1 int
- if v != nil {
- ptr1, err = graphql.UnmarshalInt(v)
- it.First = &ptr1
- }
-
- if err != nil {
- return it, err
- }
- case "last":
- var err error
- var ptr1 int
- if v != nil {
- ptr1, err = graphql.UnmarshalInt(v)
- it.Last = &ptr1
- }
-
- if err != nil {
- return it, err
- }
- }
- }
-
- return it, nil
-}
-
func (ec *executionContext) introspectSchema() *introspection.Schema {
return introspection.WrapSchema(parsedSchema)
}
@@ -2526,31 +2686,14 @@ scalar Label
type PageInfo {
# When paginating forwards, are there more items?
hasNextPage: Boolean!
-
# When paginating backwards, are there more items?
hasPreviousPage: Boolean!
-
# When paginating backwards, the cursor to continue.
# startCursor: String
-
# When paginating forwards, the cursor to continue.
# endCursor: String
}
-input ConnectionInput {
- # Returns the elements in the list that come after the specified cursor.
- after: String
-
- # Returns the elements in the list that come before the specified cursor.
- before: String
-
- # Returns the first _n_ elements from the list.
- first: Int
-
- # Returns the last _n_ elements from the list.
- last: Int
-}
-
# Represents an person in a git object.
type Person {
# The email of the person.
@@ -2560,9 +2703,9 @@ type Person {
name: String
}
-
type CommentConnection {
edges: [CommentEdge!]!
+ nodes: [Comment!]!
pageInfo: PageInfo!
totalCount: Int!
}
@@ -2594,6 +2737,7 @@ interface Authored {
type OperationConnection {
edges: [OperationEdge!]!
+ nodes: [Operation!]!
pageInfo: PageInfo!
totalCount: Int!
}
@@ -2607,7 +2751,6 @@ type OperationEdge {
interface Operation {
# The operations author.
author: Person!
-
# The datetime when this operation was issued.
date: Time!
}
@@ -2653,10 +2796,9 @@ type LabelChangeOperation implements Operation, Authored {
type BugConnection {
# A list of edges.
edges: [BugEdge!]!
-
+ nodes: [Bug!]!
# Information to aid in pagination.
pageInfo: PageInfo!
-
# Identifies the total count of items in the connection.
totalCount: Int!
}
@@ -2665,7 +2807,6 @@ type BugConnection {
type BugEdge {
# A cursor for use in pagination.
cursor: String!
-
# The item at the end of the edge.
node: Bug!
}
@@ -2679,13 +2820,40 @@ type Bug {
# A list of labels associated with the repository.
labels: [Label!]!
- comments(input: ConnectionInput!): CommentConnection!
-
- operations(input: ConnectionInput!): OperationConnection!
+ comments(
+ # Returns the elements in the list that come after the specified cursor.
+ after: String
+ # Returns the elements in the list that come before the specified cursor.
+ before: String
+ # Returns the first _n_ elements from the list.
+ first: Int
+ # Returns the last _n_ elements from the list.
+ last: Int
+ ): CommentConnection!
+
+ operations(
+ # Returns the elements in the list that come after the specified cursor.
+ after: String
+ # Returns the elements in the list that come before the specified cursor.
+ before: String
+ # Returns the first _n_ elements from the list.
+ first: Int
+ # Returns the last _n_ elements from the list.
+ last: Int
+ ): OperationConnection!
}
type Repository {
- allBugs(input: ConnectionInput!): BugConnection!
+ allBugs(
+ # Returns the elements in the list that come after the specified cursor.
+ after: String
+ # Returns the elements in the list that come before the specified cursor.
+ before: String
+ # Returns the first _n_ elements from the list.
+ first: Int
+ # Returns the last _n_ elements from the list.
+ last: Int
+ ): BugConnection!
bug(prefix: String!): Bug
}
diff --git a/graphql/models/gen_models.go b/graphql/models/gen_models.go
index aacb0d92..8a832b23 100644
--- a/graphql/models/gen_models.go
+++ b/graphql/models/gen_models.go
@@ -12,9 +12,10 @@ import (
type Authored interface{}
type BugConnection struct {
- Edges []BugEdge `json:"edges"`
- PageInfo PageInfo `json:"pageInfo"`
- TotalCount int `json:"totalCount"`
+ Edges []BugEdge `json:"edges"`
+ Nodes []bug.Snapshot `json:"nodes"`
+ PageInfo PageInfo `json:"pageInfo"`
+ TotalCount int `json:"totalCount"`
}
type BugEdge struct {
Cursor string `json:"cursor"`
@@ -22,6 +23,7 @@ type BugEdge struct {
}
type CommentConnection struct {
Edges []CommentEdge `json:"edges"`
+ Nodes []bug.Comment `json:"nodes"`
PageInfo PageInfo `json:"pageInfo"`
TotalCount int `json:"totalCount"`
}
@@ -29,21 +31,15 @@ type CommentEdge struct {
Cursor string `json:"cursor"`
Node bug.Comment `json:"node"`
}
-type ConnectionInput struct {
- After *string `json:"after"`
- Before *string `json:"before"`
- First *int `json:"first"`
- Last *int `json:"last"`
-}
-type Operation interface{}
type OperationConnection struct {
Edges []OperationEdge `json:"edges"`
+ Nodes []bug.Operation `json:"nodes"`
PageInfo PageInfo `json:"pageInfo"`
TotalCount int `json:"totalCount"`
}
type OperationEdge struct {
- Cursor string `json:"cursor"`
- Node Operation `json:"node"`
+ Cursor string `json:"cursor"`
+ Node bug.Operation `json:"node"`
}
type PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
diff --git a/graphql/models/models.go b/graphql/models/models.go
index 1f182f1a..e55dfb3e 100644
--- a/graphql/models/models.go
+++ b/graphql/models/models.go
@@ -4,6 +4,13 @@ import (
"github.com/MichaelMure/git-bug/cache"
)
+type ConnectionInput struct {
+ After *string
+ Before *string
+ First *int
+ Last *int
+}
+
type Repository struct {
Cache cache.Cacher
Repo cache.RepoCacher
diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go
index dfb5c913..014a0f31 100644
--- a/graphql/resolvers/bug.go
+++ b/graphql/resolvers/bug.go
@@ -13,7 +13,14 @@ func (bugResolver) Status(ctx context.Context, obj *bug.Snapshot) (models.Status
return convertStatus(obj.Status)
}
-func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.CommentConnection, error) {
+func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.CommentConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
+
edger := func(comment bug.Comment, offset int) connections.Edge {
return models.CommentEdge{
Node: comment,
@@ -21,31 +28,40 @@ func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, input models
}
}
- conMaker := func(edges []models.CommentEdge, info models.PageInfo, totalCount int) models.CommentConnection {
+ conMaker := func(edges []models.CommentEdge, nodes []bug.Comment, info models.PageInfo, totalCount int) (models.CommentConnection, error) {
return models.CommentConnection{
Edges: edges,
+ Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
- }
+ }, nil
}
return connections.BugCommentCon(obj.Comments, edger, conMaker, input)
}
-func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.OperationConnection, error) {
+func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, after *string, before *string, first *int, last *int) (models.OperationConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
+
edger := func(op bug.Operation, offset int) connections.Edge {
return models.OperationEdge{
- Node: op.(models.Operation),
+ Node: op,
Cursor: connections.OffsetToCursor(offset),
}
}
- conMaker := func(edges []models.OperationEdge, info models.PageInfo, totalCount int) models.OperationConnection {
+ conMaker := func(edges []models.OperationEdge, nodes []bug.Operation, info models.PageInfo, totalCount int) (models.OperationConnection, error) {
return models.OperationConnection{
Edges: edges,
+ Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
- }
+ }, nil
}
return connections.BugOperationCon(obj.Operations, edger, conMaker, input)
diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go
index 2e2872e2..388f28f5 100644
--- a/graphql/resolvers/repo.go
+++ b/graphql/resolvers/repo.go
@@ -9,7 +9,13 @@ import (
type repoResolver struct{}
-func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, input models.ConnectionInput) (models.BugConnection, error) {
+func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.BugConnection, error) {
+ input := models.ConnectionInput{
+ Before: before,
+ After: after,
+ First: first,
+ Last: last,
+ }
// Simply pass a []string with the ids to the pagination algorithm
source, err := obj.Repo.AllBugIds()
@@ -27,8 +33,9 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, input m
}
// The conMaker will finally load and compile bugs from git to replace the selected edges
- conMaker := func(lazyBugEdges []connections.LazyBugEdge, info models.PageInfo, totalCount int) (models.BugConnection, error) {
+ conMaker := func(lazyBugEdges []connections.LazyBugEdge, lazyNode []string, info models.PageInfo, totalCount int) (models.BugConnection, error) {
edges := make([]models.BugEdge, len(lazyBugEdges))
+ nodes := make([]bug.Snapshot, len(lazyBugEdges))
for i, lazyBugEdge := range lazyBugEdges {
b, err := obj.Repo.ResolveBug(lazyBugEdge.Id)
@@ -43,10 +50,12 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, input m
Cursor: lazyBugEdge.Cursor,
Node: *snap,
}
+ nodes[i] = *snap
}
return models.BugConnection{
Edges: edges,
+ Nodes: nodes,
PageInfo: info,
TotalCount: totalCount,
}, nil
@@ -64,10 +73,3 @@ func (repoResolver) Bug(ctx context.Context, obj *models.Repository, prefix stri
return b.Snapshot(), nil
}
-
-func (repoResolver) Mutation(ctx context.Context, obj *models.Repository) (models.RepositoryMutation, error) {
- return models.RepositoryMutation{
- Repo: obj.Repo,
- Cache: obj.Cache,
- }, nil
-}
diff --git a/graphql/schema.graphql b/graphql/schema.graphql
index 52623301..3a8cf02f 100644
--- a/graphql/schema.graphql
+++ b/graphql/schema.graphql
@@ -5,31 +5,14 @@ scalar Label
type PageInfo {
# When paginating forwards, are there more items?
hasNextPage: Boolean!
-
# When paginating backwards, are there more items?
hasPreviousPage: Boolean!
-
# When paginating backwards, the cursor to continue.
# startCursor: String
-
# When paginating forwards, the cursor to continue.
# endCursor: String
}
-input ConnectionInput {
- # Returns the elements in the list that come after the specified cursor.
- after: String
-
- # Returns the elements in the list that come before the specified cursor.
- before: String
-
- # Returns the first _n_ elements from the list.
- first: Int
-
- # Returns the last _n_ elements from the list.
- last: Int
-}
-
# Represents an person in a git object.
type Person {
# The email of the person.
@@ -39,9 +22,9 @@ type Person {
name: String
}
-
type CommentConnection {
edges: [CommentEdge!]!
+ nodes: [Comment!]!
pageInfo: PageInfo!
totalCount: Int!
}
@@ -73,6 +56,7 @@ interface Authored {
type OperationConnection {
edges: [OperationEdge!]!
+ nodes: [Operation!]!
pageInfo: PageInfo!
totalCount: Int!
}
@@ -86,7 +70,6 @@ type OperationEdge {
interface Operation {
# The operations author.
author: Person!
-
# The datetime when this operation was issued.
date: Time!
}
@@ -132,10 +115,9 @@ type LabelChangeOperation implements Operation, Authored {
type BugConnection {
# A list of edges.
edges: [BugEdge!]!
-
+ nodes: [Bug!]!
# Information to aid in pagination.
pageInfo: PageInfo!
-
# Identifies the total count of items in the connection.
totalCount: Int!
}
@@ -144,7 +126,6 @@ type BugConnection {
type BugEdge {
# A cursor for use in pagination.
cursor: String!
-
# The item at the end of the edge.
node: Bug!
}
@@ -158,13 +139,40 @@ type Bug {
# A list of labels associated with the repository.
labels: [Label!]!
- comments(input: ConnectionInput!): CommentConnection!
-
- operations(input: ConnectionInput!): OperationConnection!
+ comments(
+ # Returns the elements in the list that come after the specified cursor.
+ after: String
+ # Returns the elements in the list that come before the specified cursor.
+ before: String
+ # Returns the first _n_ elements from the list.
+ first: Int
+ # Returns the last _n_ elements from the list.
+ last: Int
+ ): CommentConnection!
+
+ operations(
+ # Returns the elements in the list that come after the specified cursor.
+ after: String
+ # Returns the elements in the list that come before the specified cursor.
+ before: String
+ # Returns the first _n_ elements from the list.
+ first: Int
+ # Returns the last _n_ elements from the list.
+ last: Int
+ ): OperationConnection!
}
type Repository {
- allBugs(input: ConnectionInput!): BugConnection!
+ allBugs(
+ # Returns the elements in the list that come after the specified cursor.
+ after: String
+ # Returns the elements in the list that come before the specified cursor.
+ before: String
+ # Returns the first _n_ elements from the list.
+ first: Int
+ # Returns the last _n_ elements from the list.
+ last: Int
+ ): BugConnection!
bug(prefix: String!): Bug
}