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) {
ctx, err := PrepResolve(p)
_, ctx, err := PrepResolve(p)
if err != nil {
return nil, err
}
@ -23,16 +23,19 @@ var GQLMutationAbort = NewField(func()*graphql.Field {
return nil, err
}
var node Node = nil
var node *Node = nil
context := NewReadContext(ctx.Context)
err = UseStates(context, ctx.User, NewLockMap(
NewLockInfo(ctx.Server, []string{"children"}),
err = UseStates(context, ctx.User, NewACLMap(
NewACLInfo(ctx.Server, []string{"children"}),
), 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 {
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 {
return nil, err
@ -61,7 +64,7 @@ var GQLMutationStartChild = NewField(func()*graphql.Field{
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
ctx, err := PrepResolve(p)
_, ctx, err := PrepResolve(p)
if err != nil {
return nil, err
}
@ -81,18 +84,21 @@ var GQLMutationStartChild = NewField(func()*graphql.Field{
return nil, err
}
var signal GraphSignal
var signal Signal
context := NewWriteContext(ctx.Context)
err = UseStates(context, ctx.User, NewLockMap(
NewLockInfo(ctx.Server, []string{"children"}),
err = UseStates(context, ctx.User, NewACLMap(
NewACLInfo(ctx.Server, []string{"children"}),
), 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 {
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)
return Signal(context, ctx.User, parent, signal)
return SendSignal(context, ctx.User, parent, signal)
})
if err != nil {
return nil, err

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

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

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