aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/connections/gen_bug.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-29 20:58:22 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-29 20:58:22 +0200
commitc58aa18a2d0683b0a1e6f0597724e67b500503a0 (patch)
tree06b7611ebce2a4cbe0c99f72729517cb8114e3f1 /graphql/connections/gen_bug.go
parent08f03ecf3cbbc350585acf0492966681ec449a94 (diff)
downloadgit-bug-c58aa18a2d0683b0a1e6f0597724e67b500503a0.tar.gz
graphql: lazy loading for the bug relay connection
Diffstat (limited to 'graphql/connections/gen_bug.go')
-rw-r--r--graphql/connections/gen_bug.go21
1 files changed, 9 insertions, 12 deletions
diff --git a/graphql/connections/gen_bug.go b/graphql/connections/gen_bug.go
index b43d5c11..64458669 100644
--- a/graphql/connections/gen_bug.go
+++ b/graphql/connections/gen_bug.go
@@ -7,18 +7,17 @@ package connections
import (
"fmt"
- "github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/graphql/models"
)
-type BugSnapshotEdger func(value bug.Snapshot, offset int) Edge
-type BugSnapshotConMaker func(edges []models.BugEdge, info models.PageInfo, totalCount int) models.BugConnection
+type StringEdger func(value string, offset int) Edge
+type StringConMaker func(edges []LazyBugEdge, info models.PageInfo, totalCount int) (models.BugConnection, error)
-func BugSnapshotCon(source []bug.Snapshot, edger BugSnapshotEdger, conMaker BugSnapshotConMaker, input models.ConnectionInput) (models.BugConnection, error) {
- var edges []models.BugEdge
+func StringCon(source []string, edger StringEdger, conMaker StringConMaker, input models.ConnectionInput) (models.BugConnection, error) {
+ var edges []LazyBugEdge
var pageInfo models.PageInfo
- emptyCon := conMaker(edges, pageInfo, 0)
+ emptyCon, _ := conMaker(edges, pageInfo, 0)
offset := 0
@@ -43,13 +42,13 @@ func BugSnapshotCon(source []bug.Snapshot, edger BugSnapshotEdger, conMaker BugS
break
}
- edges = append(edges, edge.(models.BugEdge))
+ edges = append(edges, edge.(LazyBugEdge))
}
} else {
- edges = make([]models.BugEdge, len(source))
+ edges = make([]LazyBugEdge, len(source))
for i, value := range source {
- edges[i] = edger(value, i+offset).(models.BugEdge)
+ edges[i] = edger(value, i+offset).(LazyBugEdge)
}
}
@@ -77,7 +76,5 @@ func BugSnapshotCon(source []bug.Snapshot, edger BugSnapshotEdger, conMaker BugS
}
}
- con := conMaker(edges, pageInfo, len(source))
-
- return con, nil
+ return conMaker(edges, pageInfo, len(source))
}