Re-added all files after rework, still need to add more complex tests

graph-rework-2
noah metz 2023-07-26 15:52:40 -06:00
parent 89c8fba39b
commit 294bcfb518
4 changed files with 33 additions and 27 deletions

@ -13,7 +13,7 @@ var GQLMutationAbort = NewField(func()*graphql.Field {
}, },
}, },
Resolve: func(p graphql.ResolveParams) (interface{}, error) { Resolve: func(p graphql.ResolveParams) (interface{}, error) {
ctx, err := PrepResolve(p) _, ctx, err := PrepResolve(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -23,16 +23,19 @@ var GQLMutationAbort = NewField(func()*graphql.Field {
return nil, err return nil, err
} }
var node Node = nil var node *Node = nil
context := NewReadContext(ctx.Context) context := NewReadContext(ctx.Context)
err = UseStates(context, ctx.User, NewLockMap( err = UseStates(context, ctx.User, NewACLMap(
NewLockInfo(ctx.Server, []string{"children"}), NewACLInfo(ctx.Server, []string{"children"}),
), func(context *StateContext) (error){ ), func(context *StateContext) (error){
node = FindChild(context, ctx.User, &ctx.Server.Thread, id) node, err = FindChild(context, ctx.User, ctx.Server, id)
if err != nil {
return err
}
if node == nil { if node == nil {
return fmt.Errorf("Failed to find ID: %s as child of server thread", id) return fmt.Errorf("Failed to find ID: %s as child of server thread", id)
} }
return Signal(context, node, ctx.User, AbortSignal) return SendSignal(context, node, ctx.User, AbortSignal)
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -61,7 +64,7 @@ var GQLMutationStartChild = NewField(func()*graphql.Field{
}, },
}, },
Resolve: func(p graphql.ResolveParams) (interface{}, error) { Resolve: func(p graphql.ResolveParams) (interface{}, error) {
ctx, err := PrepResolve(p) _, ctx, err := PrepResolve(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -81,18 +84,21 @@ var GQLMutationStartChild = NewField(func()*graphql.Field{
return nil, err return nil, err
} }
var signal GraphSignal var signal Signal
context := NewWriteContext(ctx.Context) context := NewWriteContext(ctx.Context)
err = UseStates(context, ctx.User, NewLockMap( err = UseStates(context, ctx.User, NewACLMap(
NewLockInfo(ctx.Server, []string{"children"}), NewACLInfo(ctx.Server, []string{"children"}),
), func(context *StateContext) error { ), func(context *StateContext) error {
parent := FindChild(context, ctx.User, &ctx.Server.Thread, parent_id) parent, err := FindChild(context, ctx.User, ctx.Server, parent_id)
if err != nil {
return err
}
if parent == nil { if parent == nil {
return fmt.Errorf("%s is not a child of %s", parent_id, ctx.Server.ID()) return fmt.Errorf("%s is not a child of %s", parent_id, ctx.Server.ID)
} }
signal = NewStartChildSignal(child_id, action) signal = NewStartChildSignal(child_id, action)
return Signal(context, ctx.User, parent, signal) return SendSignal(context, ctx.User, parent, signal)
}) })
if err != nil { if err != nil {
return nil, err return nil, err

@ -4,9 +4,9 @@ import (
) )
var GQLQuerySelf = &graphql.Field{ var GQLQuerySelf = &graphql.Field{
Type: GQLTypeGQLThread.Type, Type: GQLTypeBaseThread.Type,
Resolve: func(p graphql.ResolveParams) (interface{}, error) { Resolve: func(p graphql.ResolveParams) (interface{}, error) {
ctx, err := PrepResolve(p) _, ctx, err := PrepResolve(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -16,9 +16,9 @@ var GQLQuerySelf = &graphql.Field{
} }
var GQLQueryUser = &graphql.Field{ var GQLQueryUser = &graphql.Field{
Type: GQLTypeUser.Type, Type: GQLTypeBaseNode.Type,
Resolve: func(p graphql.ResolveParams) (interface{}, error) { Resolve: func(p graphql.ResolveParams) (interface{}, error) {
ctx, err := PrepResolve(p) _, ctx, err := PrepResolve(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -4,27 +4,27 @@ import (
) )
func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error) { func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error) {
return GQLSubscribeFn(p, false, func(ctx *Context, server *GQLThread, signal GraphSignal, p graphql.ResolveParams)(interface{}, error) { return GQLSubscribeFn(p, false, func(ctx *Context, server *Node, ext *GQLExt, signal Signal, p graphql.ResolveParams)(interface{}, error) {
return signal, nil return signal, nil
}) })
} }
func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error) { func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error) {
return GQLSubscribeFn(p, true, func(ctx *Context, server *GQLThread, signal GraphSignal, p graphql.ResolveParams)(interface{}, error) { return GQLSubscribeFn(p, true, func(ctx *Context, server *Node, ext *GQLExt, signal Signal, p graphql.ResolveParams)(interface{}, error) {
return server, nil return server, nil
}) })
} }
func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, fn func(*Context, *GQLThread, GraphSignal, graphql.ResolveParams)(interface{}, error))(interface{}, error) { func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, fn func(*Context, *Node, *GQLExt, Signal, graphql.ResolveParams)(interface{}, error))(interface{}, error) {
ctx, err := PrepResolve(p) _, ctx, err := PrepResolve(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
c := make(chan interface{}) c := make(chan interface{})
go func(c chan interface{}, server *GQLThread) { go func(c chan interface{}, ext *GQLExt, server *Node) {
ctx.Context.Log.Logf("gqlws", "GQL_SUBSCRIBE_THREAD_START") ctx.Context.Log.Logf("gqlws", "GQL_SUBSCRIBE_THREAD_START")
sig_c := server.NewSubscriptionChannel(1) sig_c := ext.NewSubscriptionChannel(1)
if send_nil == true { if send_nil == true {
sig_c <- nil sig_c <- nil
} }
@ -33,20 +33,20 @@ func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, fn func(*Context, *G
if ok == false { if ok == false {
return return
} }
ret, err := fn(ctx.Context, server, val, p) ret, err := fn(ctx.Context, server, ext, val, p)
if err != nil { if err != nil {
ctx.Context.Log.Logf("gqlws", "type convertor error %s", err) ctx.Context.Log.Logf("gqlws", "type convertor error %s", err)
return return
} }
c <- ret c <- ret
} }
}(c, ctx.Server) }(c, ctx.Ext, ctx.Server)
return c, nil return c, nil
} }
var GQLSubscriptionSelf = NewField(func()*graphql.Field{ var GQLSubscriptionSelf = NewField(func()*graphql.Field{
gql_subscription_self := &graphql.Field{ gql_subscription_self := &graphql.Field{
Type: GQLTypeGQLThread.Type, Type: GQLTypeBaseThread.Type,
Resolve: func(p graphql.ResolveParams) (interface{}, error) { Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return p.Source, nil return p.Source, nil
}, },

@ -10,7 +10,7 @@ import (
"crypto/elliptic" "crypto/elliptic"
) )
func TestGQLDBLoad(t * testing.T) { func TestGQL(t * testing.T) {
ctx := logTestContext(t, []string{"test", "db"}) ctx := logTestContext(t, []string{"test", "db"})
TestUserNodeType := NodeType("TEST_USER") TestUserNodeType := NodeType("TEST_USER")