graphvent/gql_mutation.go

86 lines
2.1 KiB
Go

2023-07-21 15:16:35 -06:00
package graphvent
import (
"github.com/graphql-go/graphql"
)
var GQLMutationStop = NewField(func()*graphql.Field {
gql_mutation_stop := &graphql.Field{
Type: GQLTypeSignal.Type,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.String,
2023-07-21 15:16:35 -06:00
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return StopSignal, nil
},
2023-07-21 15:16:35 -06:00
}
return gql_mutation_stop
})
var GQLMutationStartChild = NewField(func()*graphql.Field{
gql_mutation_start_child := &graphql.Field{
Type: GQLTypeSignal.Type,
Args: graphql.FieldConfigArgument{
"parent_id": &graphql.ArgumentConfig{
Type: graphql.String,
2023-07-21 15:16:35 -06:00
},
"child_id": &graphql.ArgumentConfig{
Type: graphql.String,
},
"action": &graphql.ArgumentConfig{
Type: graphql.String,
DefaultValue: "start",
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
/*_, ctx, err := PrepResolve(p)
if err != nil {
return nil, err
}
parent_id, err := ExtractID(p, "parent_id")
if err != nil {
return nil, err
}
child_id, err := ExtractID(p, "child_id")
if err != nil {
return nil, err
}
action, err := ExtractParam[string](p, "action")
if err != nil {
return nil, err
}
var signal Signal
context := NewWriteContext(ctx.Context)
err = UseStates(context, ctx.User, NewACLMap(
NewACLInfo(ctx.Server, []string{"children"}),
), func(context *StateContext) error {
parent, err := FindChild(context, ctx.User, ctx.Server, parent_id)
if err != nil {
return err
}
2023-07-24 16:04:56 -06:00
if parent == nil {
return fmt.Errorf("%s is not a child of %s", parent_id, ctx.Server.ID)
2023-07-21 15:16:35 -06:00
}
signal = NewStartChildSignal(child_id, action)
return parent.Process(context, ctx.User.ID, signal)
})
if err != nil {
return nil, err
}*/
// TODO: wait for the result of the signal to send back instead of just the signal
return nil, nil
},
2023-07-21 15:16:35 -06:00
}
return gql_mutation_start_child
})