Added Users query to GQLThread
parent
3cbb6c69e5
commit
a88c704c57
42
gql_graph.go
42
gql_graph.go
|
|
@ -385,6 +385,43 @@ func GQLLockableOwner(p graphql.ResolveParams) (interface{}, error) {
|
|||
return owner, nil
|
||||
}
|
||||
|
||||
func GQLThreadUsers(p graphql.ResolveParams) (interface{}, error) {
|
||||
node, ok := p.Source.(*GQLThread)
|
||||
if ok == false || node == nil {
|
||||
return nil, fmt.Errorf("Failed to cast source to GQLThread")
|
||||
}
|
||||
|
||||
ctx, ok := p.Context.Value("graph_context").(*Context)
|
||||
if ok == false {
|
||||
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
||||
}
|
||||
|
||||
var users []*User
|
||||
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) error {
|
||||
users = make([]*User, len(node.Users))
|
||||
i := 0
|
||||
for _, user := range(node.Users) {
|
||||
users[i] = user
|
||||
i += 1
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users, nil
|
||||
}
|
||||
|
||||
var gql_list_user *graphql.List = nil
|
||||
func GQLListUser() *graphql.List {
|
||||
if gql_list_user == nil {
|
||||
gql_list_user = graphql.NewList(GQLTypeUser())
|
||||
}
|
||||
return gql_list_user
|
||||
}
|
||||
|
||||
var gql_type_user *graphql.Object = nil
|
||||
func GQLTypeUser() * graphql.Object {
|
||||
if gql_type_user == nil {
|
||||
|
|
@ -501,6 +538,11 @@ func GQLTypeGQLThread() * graphql.Object {
|
|||
Type: GQLListLockable(),
|
||||
Resolve: GQLLockableDependencies,
|
||||
})
|
||||
|
||||
gql_type_gql_thread.AddFieldConfig("Users", &graphql.Field{
|
||||
Type: GQLListUser(),
|
||||
Resolve: GQLThreadUsers,
|
||||
})
|
||||
}
|
||||
return gql_type_gql_thread
|
||||
}
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ func TestGQLAuth(t * testing.T) {
|
|||
|
||||
url = fmt.Sprintf("http://localhost:%d/gql", port)
|
||||
ser, err := json.MarshalIndent(&GQLPayload{
|
||||
Query: "query { Self { ID } }",
|
||||
Query: "query { Self { Users { ID } } }",
|
||||
}, "", " ")
|
||||
fatalErr(t, err)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue