aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-30 00:20:04 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-30 00:20:04 +0200
commit79b3d189186783c01acb194de825976a007dbd5f (patch)
tree8369931fc77e22dff7b93de3c64d46e743592e4a
parent5b70e3452a4685112fd005fef0727930ebd2adaf (diff)
downloadgit-bug-79b3d189186783c01acb194de825976a007dbd5f.tar.gz
graphql: use an interface instead of an union for the operations for easier query
-rw-r--r--graphql/graph/gen_graph.go40
-rw-r--r--graphql/models/gen_models.go5
-rw-r--r--graphql/resolvers/bug.go2
-rw-r--r--graphql/schema.graphql9
4 files changed, 6 insertions, 50 deletions
diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go
index 386e9d01..b747e9d4 100644
--- a/graphql/graph/gen_graph.go
+++ b/graphql/graph/gen_graph.go
@@ -1060,7 +1060,7 @@ func (ec *executionContext) _OperationEdge_node(ctx context.Context, field graph
rctx.PushField(field.Alias)
defer rctx.Pop()
res := obj.Node
- return ec._OperationUnion(ctx, field.Selections, &res)
+ return ec._Operation(ctx, field.Selections, &res)
}
var pageInfoImplementors = []string{"PageInfo"}
@@ -2345,35 +2345,6 @@ func (ec *executionContext) _Operation(ctx context.Context, sel []query.Selectio
}
}
-func (ec *executionContext) _OperationUnion(ctx context.Context, sel []query.Selection, obj *models.OperationUnion) graphql.Marshaler {
- switch obj := (*obj).(type) {
- case nil:
- return graphql.Null
- case operations.CreateOperation:
- return ec._CreateOperation(ctx, sel, &obj)
- case *operations.CreateOperation:
- return ec._CreateOperation(ctx, sel, obj)
- case operations.SetTitleOperation:
- return ec._SetTitleOperation(ctx, sel, &obj)
- case *operations.SetTitleOperation:
- return ec._SetTitleOperation(ctx, sel, obj)
- case operations.AddCommentOperation:
- return ec._AddCommentOperation(ctx, sel, &obj)
- case *operations.AddCommentOperation:
- return ec._AddCommentOperation(ctx, sel, obj)
- case operations.SetStatusOperation:
- return ec._SetStatusOperation(ctx, sel, &obj)
- case *operations.SetStatusOperation:
- return ec._SetStatusOperation(ctx, sel, obj)
- case operations.LabelChangeOperation:
- return ec._LabelChangeOperation(ctx, sel, &obj)
- case *operations.LabelChangeOperation:
- return ec._LabelChangeOperation(ctx, sel, obj)
- default:
- panic(fmt.Errorf("unexpected type %T", obj))
- }
-}
-
func UnmarshalConnectionInput(v interface{}) (models.ConnectionInput, error) {
var it models.ConnectionInput
var asMap = v.(map[string]interface{})
@@ -2523,7 +2494,7 @@ type OperationConnection {
type OperationEdge {
cursor: String!
- node: OperationUnion!
+ node: Operation!
}
# An operation applied to a bug.
@@ -2572,13 +2543,6 @@ type LabelChangeOperation implements Operation, Authored {
removed: [Label!]!
}
-union OperationUnion =
- CreateOperation
- | SetTitleOperation
- | AddCommentOperation
- | SetStatusOperation
- | LabelChangeOperation
-
# The connection type for Bug.
type BugConnection {
# A list of edges.
diff --git a/graphql/models/gen_models.go b/graphql/models/gen_models.go
index a59288ec..aacb0d92 100644
--- a/graphql/models/gen_models.go
+++ b/graphql/models/gen_models.go
@@ -42,10 +42,9 @@ type OperationConnection struct {
TotalCount int `json:"totalCount"`
}
type OperationEdge struct {
- Cursor string `json:"cursor"`
- Node OperationUnion `json:"node"`
+ Cursor string `json:"cursor"`
+ Node Operation `json:"node"`
}
-type OperationUnion interface{}
type PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
HasPreviousPage bool `json:"hasPreviousPage"`
diff --git a/graphql/resolvers/bug.go b/graphql/resolvers/bug.go
index a895cdcd..dfb5c913 100644
--- a/graphql/resolvers/bug.go
+++ b/graphql/resolvers/bug.go
@@ -35,7 +35,7 @@ func (bugResolver) Comments(ctx context.Context, obj *bug.Snapshot, input models
func (bugResolver) Operations(ctx context.Context, obj *bug.Snapshot, input models.ConnectionInput) (models.OperationConnection, error) {
edger := func(op bug.Operation, offset int) connections.Edge {
return models.OperationEdge{
- Node: op.(models.OperationUnion),
+ Node: op.(models.Operation),
Cursor: connections.OffsetToCursor(offset),
}
}
diff --git a/graphql/schema.graphql b/graphql/schema.graphql
index 14b2bec5..6aadfaf1 100644
--- a/graphql/schema.graphql
+++ b/graphql/schema.graphql
@@ -79,7 +79,7 @@ type OperationConnection {
type OperationEdge {
cursor: String!
- node: OperationUnion!
+ node: Operation!
}
# An operation applied to a bug.
@@ -128,13 +128,6 @@ type LabelChangeOperation implements Operation, Authored {
removed: [Label!]!
}
-union OperationUnion =
- CreateOperation
- | SetTitleOperation
- | AddCommentOperation
- | SetStatusOperation
- | LabelChangeOperation
-
# The connection type for Bug.
type BugConnection {
# A list of edges.