2023-07-21 15:16:35 -06:00
|
|
|
package graphvent
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
)
|
|
|
|
|
2023-07-27 15:27:14 -06:00
|
|
|
var GQLMutationStop = NewField(func()*graphql.Field {
|
|
|
|
gql_mutation_stop := &graphql.Field{
|
2023-07-21 17:49:19 -06:00
|
|
|
Type: GQLTypeSignal.Type,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
"id": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
2023-07-21 15:16:35 -06:00
|
|
|
},
|
2023-07-21 17:49:19 -06:00
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-27 15:27:14 -06:00
|
|
|
return StopSignal, nil
|
2023-07-21 17:49:19 -06:00
|
|
|
},
|
2023-07-21 15:16:35 -06:00
|
|
|
}
|
|
|
|
|
2023-07-27 15:27:14 -06:00
|
|
|
return gql_mutation_stop
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
},
|
2023-07-21 17:49:19 -06:00
|
|
|
"child_id": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
"action": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
DefaultValue: "start",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-27 15:27:14 -06:00
|
|
|
/*_, ctx, err := PrepResolve(p)
|
2023-07-21 17:49:19 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-07-26 15:52:40 -06:00
|
|
|
var signal Signal
|
2023-07-23 17:57:47 -06:00
|
|
|
context := NewWriteContext(ctx.Context)
|
2023-07-26 15:52:40 -06:00
|
|
|
err = UseStates(context, ctx.User, NewACLMap(
|
|
|
|
NewACLInfo(ctx.Server, []string{"children"}),
|
2023-07-23 17:57:47 -06:00
|
|
|
), func(context *StateContext) error {
|
2023-07-26 15:52:40 -06:00
|
|
|
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 {
|
2023-07-26 15:52:40 -06:00
|
|
|
return fmt.Errorf("%s is not a child of %s", parent_id, ctx.Server.ID)
|
2023-07-21 15:16:35 -06:00
|
|
|
}
|
2023-07-22 20:21:17 -06:00
|
|
|
|
2023-07-23 21:14:15 -06:00
|
|
|
signal = NewStartChildSignal(child_id, action)
|
2023-07-27 01:30:32 -06:00
|
|
|
return parent.Process(context, ctx.User.ID, signal)
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-07-27 15:27:14 -06:00
|
|
|
}*/
|
2023-07-21 17:49:19 -06:00
|
|
|
|
|
|
|
// TODO: wait for the result of the signal to send back instead of just the signal
|
2023-07-27 15:27:14 -06:00
|
|
|
return nil, nil
|
2023-07-21 17:49:19 -06:00
|
|
|
},
|
2023-07-21 15:16:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return gql_mutation_start_child
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
|
|
|
|