aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cache/query.go7
-rw-r--r--graphql/graph/gen_graph.go27
-rw-r--r--graphql/resolvers/repo.go18
-rw-r--r--graphql/schema.graphql2
4 files changed, 42 insertions, 12 deletions
diff --git a/cache/query.go b/cache/query.go
index 198adfc9..6ffa6510 100644
--- a/cache/query.go
+++ b/cache/query.go
@@ -12,9 +12,12 @@ type Query struct {
OrderDirection
}
-// Return an identity query
+// Return an identity query with default sorting (creation-desc)
func NewQuery() *Query {
- return &Query{}
+ return &Query{
+ OrderBy: OrderByCreation,
+ OrderDirection: OrderDescending,
+ }
}
// ParseQuery parse a query DSL
diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go
index 798962e3..a8be6cd3 100644
--- a/graphql/graph/gen_graph.go
+++ b/graphql/graph/gen_graph.go
@@ -53,7 +53,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, after *string, before *string, first *int, last *int) (models.BugConnection, error)
+ Repository_allBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, query *string) (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)
@@ -103,7 +103,7 @@ type QueryResolver interface {
Repository(ctx context.Context, id string) (*models.Repository, error)
}
type RepositoryResolver interface {
- AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.BugConnection, error)
+ AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, query *string) (models.BugConnection, error)
Bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error)
}
type SetStatusOperationResolver interface {
@@ -182,8 +182,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, 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_allBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, query *string) (models.BugConnection, error) {
+ return s.r.Repository().AllBugs(ctx, obj, after, before, first, last, query)
}
func (s shortMapper) Repository_bug(ctx context.Context, obj *models.Repository, prefix string) (*bug.Snapshot, error) {
@@ -2248,6 +2248,21 @@ func (ec *executionContext) _Repository_allBugs(ctx context.Context, field graph
}
}
args["last"] = arg3
+ var arg4 *string
+ if tmp, ok := field.Args["query"]; ok {
+ var err error
+ var ptr1 string
+ if tmp != nil {
+ ptr1, err = graphql.UnmarshalString(tmp)
+ arg4 = &ptr1
+ }
+
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ }
+ args["query"] = arg4
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
Object: "Repository",
Args: args,
@@ -2263,7 +2278,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["after"].(*string), args["before"].(*string), args["first"].(*int), args["last"].(*int))
+ return ec.resolvers.Repository_allBugs(ctx, obj, args["after"].(*string), args["before"].(*string), args["first"].(*int), args["last"].(*int), args["query"].(*string))
})
if err != nil {
ec.Error(ctx, err)
@@ -3457,6 +3472,8 @@ type Repository {
first: Int
# Returns the last _n_ elements from the list.
last: Int
+ # A query to select and order bugs
+ query: String
): BugConnection!
bug(prefix: String!): Bug
}
diff --git a/graphql/resolvers/repo.go b/graphql/resolvers/repo.go
index 7922256f..c696ff34 100644
--- a/graphql/resolvers/repo.go
+++ b/graphql/resolvers/repo.go
@@ -11,7 +11,7 @@ import (
type repoResolver struct{}
-func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int) (models.BugConnection, error) {
+func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *string, before *string, first *int, last *int, queryStr *string) (models.BugConnection, error) {
input := models.ConnectionInput{
Before: before,
After: after,
@@ -19,11 +19,19 @@ func (repoResolver) AllBugs(ctx context.Context, obj *models.Repository, after *
Last: last,
}
+ var query *cache.Query
+ if queryStr != nil {
+ query2, err := cache.ParseQuery(*queryStr)
+ if err != nil {
+ return models.BugConnection{}, err
+ }
+ query = query2
+ } else {
+ query = cache.NewQuery()
+ }
+
// Simply pass a []string with the ids to the pagination algorithm
- source := obj.Repo.QueryBugs(&cache.Query{
- OrderBy: cache.OrderByCreation,
- OrderDirection: cache.OrderAscending,
- })
+ source := obj.Repo.QueryBugs(query)
// The edger create a custom edge holding just the id
edger := func(id string, offset int) connections.Edge {
diff --git a/graphql/schema.graphql b/graphql/schema.graphql
index 5910984d..779331c4 100644
--- a/graphql/schema.graphql
+++ b/graphql/schema.graphql
@@ -180,6 +180,8 @@ type Repository {
first: Int
# Returns the last _n_ elements from the list.
last: Int
+ # A query to select and order bugs
+ query: String
): BugConnection!
bug(prefix: String!): Bug
}