Added stopServer gql mutation

gql_cataclysm
noah metz 2023-07-31 17:27:54 -06:00
parent d8355ab786
commit e7d94414d5
1 changed files with 23 additions and 1 deletions

@ -774,11 +774,16 @@ func NewGQLExtContext() *GQLExtContext {
Fields: graphql.Fields{},
})
mutation := graphql.NewObject(graphql.ObjectConfig{
Name: "Mutation",
Fields: graphql.Fields{},
})
context := GQLExtContext{
Schema: graphql.Schema{},
Types: []graphql.Type{},
Query: query,
Mutation: nil,
Mutation: mutation,
Subscription: nil,
NodeTypes: map[NodeType]*graphql.Object{},
Interfaces: map[string]*Interface{},
@ -898,6 +903,23 @@ func NewGQLExtContext() *GQLExtContext {
panic(err)
}
context.Mutation.AddFieldConfig("stopServer", &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
ctx, err := PrepResolve(p)
if err != nil {
return nil, err
}
err = ctx.Context.Send(ctx.User, ctx.Server.ID, StringSignal{NewDirectSignal(GQLStateSignalType), "stop_server"})
if err != nil {
return nil, err
}
return "stop_sent", nil
},
})
context.Query.AddFieldConfig("Self", &graphql.Field{
Type: context.Interfaces["Node"].Interface,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {