2023-06-25 20:20:59 -06:00
|
|
|
package graphvent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
"reflect"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
var gql_interface_graph_node *graphql.Interface = nil
|
2023-07-09 20:30:19 -06:00
|
|
|
func GQLInterfaceNode() *graphql.Interface {
|
2023-06-25 20:20:59 -06:00
|
|
|
if gql_interface_graph_node == nil {
|
|
|
|
gql_interface_graph_node = graphql.NewInterface(graphql.InterfaceConfig{
|
2023-07-09 20:30:19 -06:00
|
|
|
Name: "Node",
|
2023-06-25 20:20:59 -06:00
|
|
|
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-27 12:53:10 -06:00
|
|
|
if ok == false {
|
|
|
|
return nil
|
|
|
|
}
|
2023-06-27 10:30:11 -06:00
|
|
|
|
2023-07-01 13:03:28 -06:00
|
|
|
valid_nodes := ctx.GQL.ValidNodes
|
|
|
|
node_type := ctx.GQL.NodeType
|
2023-06-27 10:30:11 -06:00
|
|
|
p_type := reflect.TypeOf(p.Value)
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
for key, value := range(valid_nodes) {
|
2023-06-27 10:30:11 -06:00
|
|
|
if p_type == key {
|
2023-06-25 20:20:59 -06:00
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 10:30:11 -06:00
|
|
|
|
2023-07-01 13:03:28 -06:00
|
|
|
if p_type.Implements(node_type) {
|
2023-07-10 21:15:01 -06:00
|
|
|
return GQLTypeGraphNode()
|
2023-06-27 10:30:11 -06:00
|
|
|
}
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_interface_graph_node.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return gql_interface_graph_node
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_list_thread *graphql.List = nil
|
|
|
|
func GQLListThread() *graphql.List {
|
|
|
|
if gql_list_thread == nil {
|
|
|
|
gql_list_thread = graphql.NewList(GQLInterfaceThread())
|
|
|
|
}
|
|
|
|
return gql_list_thread
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_interface_thread *graphql.Interface = nil
|
|
|
|
func GQLInterfaceThread() *graphql.Interface {
|
|
|
|
if gql_interface_thread == nil {
|
|
|
|
gql_interface_thread = graphql.NewInterface(graphql.InterfaceConfig{
|
|
|
|
Name: "Thread",
|
|
|
|
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-27 12:53:10 -06:00
|
|
|
if ok == false {
|
|
|
|
return nil
|
|
|
|
}
|
2023-06-27 10:30:11 -06:00
|
|
|
|
2023-07-01 13:03:28 -06:00
|
|
|
valid_threads := ctx.GQL.ValidThreads
|
|
|
|
thread_type := ctx.GQL.ThreadType
|
2023-06-27 10:30:11 -06:00
|
|
|
p_type := reflect.TypeOf(p.Value)
|
|
|
|
|
|
|
|
for key, value := range(valid_threads) {
|
|
|
|
if p_type == key {
|
2023-06-25 20:20:59 -06:00
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 10:30:11 -06:00
|
|
|
|
2023-07-01 13:03:28 -06:00
|
|
|
if p_type.Implements(thread_type) {
|
2023-07-10 21:15:01 -06:00
|
|
|
return GQLTypeSimpleThread()
|
2023-06-27 10:30:11 -06:00
|
|
|
}
|
|
|
|
|
2023-07-01 13:03:28 -06:00
|
|
|
ctx.Log.Logf("gql", "Found no type that matches %+v: %+v", p_type, p_type.Implements(thread_type))
|
2023-06-25 20:20:59 -06:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_interface_thread.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
})
|
2023-06-25 20:42:35 -06:00
|
|
|
|
|
|
|
gql_interface_thread.AddFieldConfig("Name", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
})
|
|
|
|
|
2023-07-11 16:24:19 -06:00
|
|
|
gql_interface_thread.AddFieldConfig("State", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
})
|
|
|
|
|
2023-06-25 20:42:35 -06:00
|
|
|
gql_interface_thread.AddFieldConfig("Children", &graphql.Field{
|
|
|
|
Type: GQLListThread(),
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_interface_thread.AddFieldConfig("Parent", &graphql.Field{
|
|
|
|
Type: GQLInterfaceThread(),
|
|
|
|
})
|
2023-06-28 01:26:44 -06:00
|
|
|
|
2023-06-28 01:27:47 -06:00
|
|
|
gql_interface_thread.AddFieldConfig("Requirements", &graphql.Field{
|
2023-06-28 01:26:44 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
})
|
|
|
|
|
2023-06-28 01:27:47 -06:00
|
|
|
gql_interface_thread.AddFieldConfig("Dependencies", &graphql.Field{
|
2023-06-28 01:26:44 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
})
|
|
|
|
|
2023-06-28 01:27:47 -06:00
|
|
|
gql_interface_thread.AddFieldConfig("Owner", &graphql.Field{
|
2023-06-28 01:26:44 -06:00
|
|
|
Type: GQLInterfaceLockable(),
|
|
|
|
})
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return gql_interface_thread
|
|
|
|
}
|
|
|
|
|
2023-06-25 20:42:35 -06:00
|
|
|
var gql_list_lockable *graphql.List = nil
|
|
|
|
func GQLListLockable() *graphql.List {
|
|
|
|
if gql_list_lockable == nil {
|
|
|
|
gql_list_lockable = graphql.NewList(GQLInterfaceLockable())
|
|
|
|
}
|
|
|
|
return gql_list_lockable
|
|
|
|
}
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
var gql_interface_lockable *graphql.Interface = nil
|
|
|
|
func GQLInterfaceLockable() *graphql.Interface {
|
|
|
|
if gql_interface_lockable == nil {
|
|
|
|
gql_interface_lockable = graphql.NewInterface(graphql.InterfaceConfig{
|
|
|
|
Name: "Lockable",
|
|
|
|
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-27 12:53:10 -06:00
|
|
|
if ok == false {
|
|
|
|
return nil
|
|
|
|
}
|
2023-06-27 10:30:11 -06:00
|
|
|
|
2023-07-01 13:03:28 -06:00
|
|
|
valid_lockables := ctx.GQL.ValidLockables
|
|
|
|
lockable_type := ctx.GQL.LockableType
|
2023-06-27 10:30:11 -06:00
|
|
|
p_type := reflect.TypeOf(p.Value)
|
|
|
|
|
|
|
|
for key, value := range(valid_lockables) {
|
|
|
|
if p_type == key {
|
2023-06-25 20:20:59 -06:00
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 10:30:11 -06:00
|
|
|
|
2023-07-01 13:03:28 -06:00
|
|
|
if p_type.Implements(lockable_type) {
|
2023-07-10 21:15:01 -06:00
|
|
|
return GQLTypeSimpleLockable()
|
2023-06-27 10:30:11 -06:00
|
|
|
}
|
2023-06-25 20:20:59 -06:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_interface_lockable.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_interface_lockable.AddFieldConfig("Name", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
})
|
2023-06-25 20:42:35 -06:00
|
|
|
|
|
|
|
if gql_list_lockable == nil {
|
|
|
|
gql_list_lockable = graphql.NewList(gql_interface_lockable)
|
|
|
|
}
|
|
|
|
|
|
|
|
gql_interface_lockable.AddFieldConfig("Requirements", &graphql.Field{
|
2023-06-28 01:45:57 -06:00
|
|
|
Type: gql_list_lockable,
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
gql_interface_lockable.AddFieldConfig("Dependencies", &graphql.Field{
|
2023-06-28 01:45:57 -06:00
|
|
|
Type: gql_list_lockable,
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
gql_interface_lockable.AddFieldConfig("Owner", &graphql.Field{
|
2023-06-28 01:40:32 -06:00
|
|
|
Type: gql_interface_lockable,
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return gql_interface_lockable
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLNodeID(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-09 20:30:19 -06:00
|
|
|
node, ok := p.Source.(Node)
|
2023-06-25 20:20:59 -06:00
|
|
|
if ok == false || node == nil {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast source to Node")
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
return node.ID(), nil
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
func GQLThreadListen(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(*GQLThread)
|
2023-06-25 20:20:59 -06:00
|
|
|
if ok == false || node == nil {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast source to GQLThread")
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:20:59 -06:00
|
|
|
if ok == false {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
listen := ""
|
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) (error) {
|
|
|
|
listen = node.Listen
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
return listen, nil
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
func GQLThreadParent(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(Thread)
|
2023-06-25 20:20:59 -06:00
|
|
|
if ok == false || node == nil {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast source to Thread")
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:20:59 -06:00
|
|
|
if ok == false {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
var parent Thread = nil
|
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) (error) {
|
|
|
|
parent = node.Parent()
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
return parent, nil
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-11 16:24:19 -06:00
|
|
|
func GQLThreadState(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(Thread)
|
|
|
|
if ok == false || node == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to cast source to Thread")
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
|
|
|
if ok == false {
|
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
|
|
|
}
|
|
|
|
|
|
|
|
var state string
|
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) (error) {
|
|
|
|
state = node.State()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return state, nil
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
func GQLThreadChildren(p graphql.ResolveParams) (interface{}, error) {
|
2023-06-25 20:42:35 -06:00
|
|
|
node, ok := p.Source.(Thread)
|
|
|
|
if ok == false || node == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to cast source to Thread")
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:42:35 -06:00
|
|
|
if ok == false {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
var children []Thread = nil
|
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) (error) {
|
|
|
|
children = node.Children()
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
return children, nil
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
func GQLLockableName(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(Lockable)
|
2023-06-25 20:42:35 -06:00
|
|
|
if ok == false || node == nil {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast source to Lockable")
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
|
|
|
if ok == false || node == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
name := ""
|
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) error {
|
|
|
|
name = node.Name()
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
return name, nil
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func GQLLockableRequirements(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(Lockable)
|
|
|
|
if ok == false || node == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to cast source to Lockable")
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:42:35 -06:00
|
|
|
if ok == false {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-06-28 00:48:49 -06:00
|
|
|
var requirements []Lockable = nil
|
2023-07-09 20:30:19 -06:00
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) (error) {
|
|
|
|
requirements = node.Requirements()
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-06-28 00:48:49 -06:00
|
|
|
return requirements, nil
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func GQLLockableDependencies(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(Lockable)
|
|
|
|
if ok == false || node == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to cast source to Lockable")
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:42:35 -06:00
|
|
|
if ok == false {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-06-28 00:48:49 -06:00
|
|
|
var dependencies []Lockable = nil
|
2023-07-09 20:30:19 -06:00
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) (error) {
|
|
|
|
dependencies = node.Dependencies()
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-06-28 00:48:49 -06:00
|
|
|
return dependencies, nil
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func GQLLockableOwner(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(Lockable)
|
|
|
|
if ok == false || node == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to cast source to Lockable")
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:42:35 -06:00
|
|
|
if ok == false {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
var owner Node = nil
|
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) (error) {
|
|
|
|
owner = node.Owner()
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:42:35 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-06-28 00:48:49 -06:00
|
|
|
return owner, nil
|
2023-06-25 20:42:35 -06:00
|
|
|
}
|
|
|
|
|
2023-07-20 22:17:45 -06:00
|
|
|
func GQLThreadUsers(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
node, ok := p.Source.(*GQLThread)
|
|
|
|
if ok == false || node == nil {
|
|
|
|
return nil, fmt.Errorf("Failed to cast source to GQLThread")
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
|
|
|
if ok == false {
|
|
|
|
return nil, fmt.Errorf("Failed to cast context graph_context to Context")
|
|
|
|
}
|
|
|
|
|
|
|
|
var users []*User
|
|
|
|
err := UseStates(ctx, []Node{node}, func(nodes NodeMap) error {
|
|
|
|
users = make([]*User, len(node.Users))
|
|
|
|
i := 0
|
|
|
|
for _, user := range(node.Users) {
|
|
|
|
users[i] = user
|
|
|
|
i += 1
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return users, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_list_user *graphql.List = nil
|
|
|
|
func GQLListUser() *graphql.List {
|
|
|
|
if gql_list_user == nil {
|
|
|
|
gql_list_user = graphql.NewList(GQLTypeUser())
|
|
|
|
}
|
|
|
|
return gql_list_user
|
|
|
|
}
|
|
|
|
|
2023-07-20 22:03:25 -06:00
|
|
|
var gql_type_user *graphql.Object = nil
|
|
|
|
func GQLTypeUser() * graphql.Object {
|
|
|
|
if gql_type_user == nil {
|
|
|
|
gql_type_user = graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "User",
|
2023-07-20 00:24:22 -06:00
|
|
|
Interfaces: []*graphql.Interface{
|
|
|
|
GQLInterfaceNode(),
|
|
|
|
GQLInterfaceLockable(),
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
|
|
|
if ok == false {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
lockable_type := ctx.GQL.LockableType
|
|
|
|
value_type := reflect.TypeOf(p.Value)
|
|
|
|
|
|
|
|
if value_type.Implements(lockable_type) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-07-20 22:03:25 -06:00
|
|
|
gql_type_user.AddFieldConfig("ID", &graphql.Field{
|
2023-07-20 00:24:22 -06:00
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLNodeID,
|
|
|
|
})
|
|
|
|
|
2023-07-20 22:03:25 -06:00
|
|
|
gql_type_user.AddFieldConfig("Name", &graphql.Field{
|
2023-07-20 00:24:22 -06:00
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLLockableName,
|
|
|
|
})
|
|
|
|
|
2023-07-20 22:03:25 -06:00
|
|
|
gql_type_user.AddFieldConfig("Requirements", &graphql.Field{
|
2023-07-20 00:24:22 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableRequirements,
|
|
|
|
})
|
|
|
|
|
2023-07-20 22:03:25 -06:00
|
|
|
gql_type_user.AddFieldConfig("Owner", &graphql.Field{
|
2023-07-20 00:24:22 -06:00
|
|
|
Type: GQLInterfaceLockable(),
|
|
|
|
Resolve: GQLLockableOwner,
|
|
|
|
})
|
|
|
|
|
2023-07-20 22:03:25 -06:00
|
|
|
gql_type_user.AddFieldConfig("Dependencies", &graphql.Field{
|
2023-07-20 00:24:22 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableDependencies,
|
|
|
|
})
|
|
|
|
}
|
2023-07-20 22:03:25 -06:00
|
|
|
return gql_type_user
|
2023-07-20 00:24:22 -06:00
|
|
|
}
|
2023-06-25 20:42:35 -06:00
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
var gql_type_gql_thread *graphql.Object = nil
|
|
|
|
func GQLTypeGQLThread() * graphql.Object {
|
|
|
|
if gql_type_gql_thread == nil {
|
|
|
|
gql_type_gql_thread = graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "GQLThread",
|
|
|
|
Interfaces: []*graphql.Interface{
|
2023-07-09 20:30:19 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-25 20:20:59 -06:00
|
|
|
GQLInterfaceThread(),
|
2023-06-25 20:42:35 -06:00
|
|
|
GQLInterfaceLockable(),
|
2023-06-25 20:20:59 -06:00
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
_, ok := p.Value.(*GQLThread)
|
|
|
|
return ok
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLNodeID,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("Name", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
2023-07-09 20:30:19 -06:00
|
|
|
Resolve: GQLLockableName,
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
|
|
|
|
2023-07-11 16:24:19 -06:00
|
|
|
gql_type_gql_thread.AddFieldConfig("State", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLThreadState,
|
|
|
|
})
|
|
|
|
|
2023-06-25 20:42:35 -06:00
|
|
|
gql_type_gql_thread.AddFieldConfig("Children", &graphql.Field{
|
|
|
|
Type: GQLListThread(),
|
|
|
|
Resolve: GQLThreadChildren,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("Parent", &graphql.Field{
|
|
|
|
Type: GQLInterfaceThread(),
|
|
|
|
Resolve: GQLThreadParent,
|
|
|
|
})
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
gql_type_gql_thread.AddFieldConfig("Listen", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLThreadListen,
|
|
|
|
})
|
2023-06-25 20:42:35 -06:00
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("Requirements", &graphql.Field{
|
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableRequirements,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("Owner", &graphql.Field{
|
|
|
|
Type: GQLInterfaceLockable(),
|
|
|
|
Resolve: GQLLockableOwner,
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("Dependencies", &graphql.Field{
|
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableDependencies,
|
|
|
|
})
|
2023-07-20 22:17:45 -06:00
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("Users", &graphql.Field{
|
|
|
|
Type: GQLListUser(),
|
|
|
|
Resolve: GQLThreadUsers,
|
|
|
|
})
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
return gql_type_gql_thread
|
|
|
|
}
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
var gql_type_simple_thread *graphql.Object = nil
|
|
|
|
func GQLTypeSimpleThread() * graphql.Object {
|
|
|
|
if gql_type_simple_thread == nil {
|
|
|
|
gql_type_simple_thread = graphql.NewObject(graphql.ObjectConfig{
|
2023-07-11 16:24:19 -06:00
|
|
|
Name: "SimpleThread",
|
2023-06-25 20:20:59 -06:00
|
|
|
Interfaces: []*graphql.Interface{
|
2023-07-09 20:30:19 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-25 20:20:59 -06:00
|
|
|
GQLInterfaceThread(),
|
2023-06-25 20:42:35 -06:00
|
|
|
GQLInterfaceLockable(),
|
2023-06-25 20:20:59 -06:00
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:20:59 -06:00
|
|
|
if ok == false {
|
|
|
|
return false
|
|
|
|
}
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-07-01 13:11:46 -06:00
|
|
|
thread_type := ctx.GQL.ThreadType
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
value_type := reflect.TypeOf(p.Value)
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-07-01 13:11:46 -06:00
|
|
|
if value_type.Implements(thread_type) {
|
2023-06-27 13:07:23 -06:00
|
|
|
return true
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
return false
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("ID", &graphql.Field{
|
2023-06-25 20:20:59 -06:00
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLNodeID,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("Name", &graphql.Field{
|
2023-06-25 20:20:59 -06:00
|
|
|
Type: graphql.String,
|
2023-07-09 20:30:19 -06:00
|
|
|
Resolve: GQLLockableName,
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
2023-06-25 20:42:35 -06:00
|
|
|
|
2023-07-11 16:24:19 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("State", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLThreadState,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("Children", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLListThread(),
|
|
|
|
Resolve: GQLThreadChildren,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("Parent", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLInterfaceThread(),
|
|
|
|
Resolve: GQLThreadParent,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("Requirements", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableRequirements,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("Owner", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLInterfaceLockable(),
|
|
|
|
Resolve: GQLLockableOwner,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_thread.AddFieldConfig("Dependencies", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableDependencies,
|
|
|
|
})
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
2023-07-10 21:15:01 -06:00
|
|
|
return gql_type_simple_thread
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
var gql_type_simple_lockable *graphql.Object = nil
|
|
|
|
func GQLTypeSimpleLockable() * graphql.Object {
|
|
|
|
if gql_type_simple_lockable == nil {
|
|
|
|
gql_type_simple_lockable = graphql.NewObject(graphql.ObjectConfig{
|
2023-07-11 16:24:19 -06:00
|
|
|
Name: "SimpleLockable",
|
2023-06-25 20:20:59 -06:00
|
|
|
Interfaces: []*graphql.Interface{
|
2023-07-09 20:30:19 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-28 01:49:45 -06:00
|
|
|
GQLInterfaceLockable(),
|
2023-06-25 20:20:59 -06:00
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-27 13:07:23 -06:00
|
|
|
if ok == false {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-07-01 13:11:46 -06:00
|
|
|
lockable_type := ctx.GQL.LockableType
|
2023-06-25 20:20:59 -06:00
|
|
|
value_type := reflect.TypeOf(p.Value)
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-07-01 13:11:46 -06:00
|
|
|
if value_type.Implements(lockable_type) {
|
2023-06-27 13:07:23 -06:00
|
|
|
return true
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
return false
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_lockable.AddFieldConfig("ID", &graphql.Field{
|
2023-06-25 20:20:59 -06:00
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLNodeID,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_lockable.AddFieldConfig("Name", &graphql.Field{
|
2023-06-25 20:20:59 -06:00
|
|
|
Type: graphql.String,
|
2023-07-09 20:30:19 -06:00
|
|
|
Resolve: GQLLockableName,
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
2023-06-25 20:42:35 -06:00
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_lockable.AddFieldConfig("Requirements", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableRequirements,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_lockable.AddFieldConfig("Owner", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLInterfaceLockable(),
|
|
|
|
Resolve: GQLLockableOwner,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_lockable.AddFieldConfig("Dependencies", &graphql.Field{
|
2023-06-25 20:42:35 -06:00
|
|
|
Type: GQLListLockable(),
|
|
|
|
Resolve: GQLLockableDependencies,
|
|
|
|
})
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
2023-07-10 21:15:01 -06:00
|
|
|
return gql_type_simple_lockable
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
var gql_type_simple_node *graphql.Object = nil
|
|
|
|
func GQLTypeGraphNode() * graphql.Object {
|
|
|
|
if gql_type_simple_node == nil {
|
|
|
|
gql_type_simple_node = graphql.NewObject(graphql.ObjectConfig{
|
2023-07-11 16:24:19 -06:00
|
|
|
Name: "GraphNode",
|
2023-06-25 20:20:59 -06:00
|
|
|
Interfaces: []*graphql.Interface{
|
2023-07-09 20:30:19 -06:00
|
|
|
GQLInterfaceNode(),
|
2023-06-25 20:20:59 -06:00
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-27 13:07:23 -06:00
|
|
|
if ok == false {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-07-01 13:11:46 -06:00
|
|
|
node_type := ctx.GQL.NodeType
|
2023-06-25 20:20:59 -06:00
|
|
|
value_type := reflect.TypeOf(p.Value)
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-07-01 13:11:46 -06:00
|
|
|
if value_type.Implements(node_type) {
|
2023-06-27 13:07:23 -06:00
|
|
|
return true
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
2023-06-27 13:07:23 -06:00
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
return false
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_node.AddFieldConfig("ID", &graphql.Field{
|
2023-06-25 20:20:59 -06:00
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLNodeID,
|
|
|
|
})
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
gql_type_simple_node.AddFieldConfig("Name", &graphql.Field{
|
2023-06-25 20:20:59 -06:00
|
|
|
Type: graphql.String,
|
2023-07-09 20:30:19 -06:00
|
|
|
Resolve: GQLLockableName,
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-10 21:15:01 -06:00
|
|
|
return gql_type_simple_node
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func GQLSignalFn(p graphql.ResolveParams, fn func(GraphSignal, graphql.ResolveParams)(interface{}, error))(interface{}, error) {
|
|
|
|
if signal, ok := p.Source.(GraphSignal); ok {
|
|
|
|
return fn(signal, p)
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("Failed to cast source to event")
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLSignalType(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLSignalFn(p, func(signal GraphSignal, p graphql.ResolveParams)(interface{}, error){
|
|
|
|
return signal.Type(), nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLSignalSource(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLSignalFn(p, func(signal GraphSignal, p graphql.ResolveParams)(interface{}, error){
|
|
|
|
return signal.Source(), nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLSignalDirection(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLSignalFn(p, func(signal GraphSignal, p graphql.ResolveParams)(interface{}, error){
|
2023-06-25 21:00:00 -06:00
|
|
|
direction := signal.Direction()
|
|
|
|
if direction == Up {
|
|
|
|
return "up", nil
|
|
|
|
} else if direction == Down {
|
|
|
|
return "down", nil
|
|
|
|
} else if direction == Direct {
|
|
|
|
return "direct", nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("Invalid direction: %+v", direction)
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLSignalString(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return GQLSignalFn(p, func(signal GraphSignal, p graphql.ResolveParams)(interface{}, error){
|
|
|
|
return signal.String(), nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var gql_type_signal *graphql.Object = nil
|
|
|
|
func GQLTypeSignal() *graphql.Object {
|
|
|
|
if gql_type_signal == nil {
|
|
|
|
gql_type_signal = graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "SignalOut",
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
_, ok := p.Value.(GraphSignal)
|
|
|
|
return ok
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
|
|
|
gql_type_signal.AddFieldConfig("Type", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLSignalType,
|
|
|
|
})
|
|
|
|
gql_type_signal.AddFieldConfig("Source", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLSignalSource,
|
|
|
|
})
|
|
|
|
gql_type_signal.AddFieldConfig("Direction", &graphql.Field{
|
2023-06-25 21:00:00 -06:00
|
|
|
Type: graphql.String,
|
2023-06-25 20:20:59 -06:00
|
|
|
Resolve: GQLSignalDirection,
|
|
|
|
})
|
|
|
|
gql_type_signal.AddFieldConfig("String", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLSignalString,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return gql_type_signal
|
|
|
|
}
|
|
|
|
|
|
|
|
var gql_type_signal_input *graphql.InputObject = nil
|
|
|
|
func GQLTypeSignalInput() *graphql.InputObject {
|
|
|
|
if gql_type_signal_input == nil {
|
|
|
|
gql_type_signal_input = graphql.NewInputObject(graphql.InputObjectConfig{
|
|
|
|
Name: "SignalIn",
|
|
|
|
Fields: graphql.InputObjectConfigFieldMap{},
|
|
|
|
})
|
|
|
|
gql_type_signal_input.AddFieldConfig("Type", &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.String,
|
2023-06-25 21:00:00 -06:00
|
|
|
DefaultValue: "cancel",
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
2023-06-25 21:00:00 -06:00
|
|
|
gql_type_signal_input.AddFieldConfig("Direction", &graphql.InputObjectFieldConfig{
|
2023-06-25 20:20:59 -06:00
|
|
|
Type: graphql.String,
|
2023-06-25 21:00:00 -06:00
|
|
|
DefaultValue: "down",
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return gql_type_signal_input
|
|
|
|
}
|
|
|
|
|
|
|
|
func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-09 20:30:19 -06:00
|
|
|
return GQLSubscribeFn(p, false, func(ctx *Context, server *GQLThread, signal GraphSignal, p graphql.ResolveParams)(interface{}, error) {
|
2023-06-25 20:20:59 -06:00
|
|
|
return signal, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-03 18:58:15 -06:00
|
|
|
func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-09 20:30:19 -06:00
|
|
|
return GQLSubscribeFn(p, true, func(ctx *Context, server *GQLThread, signal GraphSignal, p graphql.ResolveParams)(interface{}, error) {
|
2023-07-03 19:37:04 -06:00
|
|
|
return server, nil
|
2023-07-03 18:58:15 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, fn func(*Context, *GQLThread, GraphSignal, graphql.ResolveParams)(interface{}, error))(interface{}, error) {
|
2023-06-25 20:20:59 -06:00
|
|
|
server, ok := p.Context.Value("gql_server").(*GQLThread)
|
|
|
|
if ok == false {
|
|
|
|
return nil, fmt.Errorf("Failed to get gql_server from context and cast to GQLServer")
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
ctx, ok := p.Context.Value("graph_context").(*Context)
|
2023-06-25 20:20:59 -06:00
|
|
|
if ok == false {
|
2023-07-09 20:30:19 -06:00
|
|
|
return nil, fmt.Errorf("Failed to get graph_context from context and cast to Context")
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
c := make(chan interface{})
|
|
|
|
go func(c chan interface{}, server *GQLThread) {
|
2023-07-03 19:19:23 -06:00
|
|
|
ctx.Log.Logf("gqlws", "GQL_SUBSCRIBE_THREAD_START")
|
2023-07-09 20:30:19 -06:00
|
|
|
sig_c := UpdateChannel(server, 1, RandID())
|
2023-07-03 19:46:01 -06:00
|
|
|
if send_nil == true {
|
|
|
|
sig_c <- nil
|
|
|
|
}
|
2023-06-25 20:20:59 -06:00
|
|
|
for {
|
|
|
|
val, ok := <- sig_c
|
|
|
|
if ok == false {
|
|
|
|
return
|
|
|
|
}
|
2023-07-03 19:46:01 -06:00
|
|
|
ret, err := fn(ctx, server, val, p)
|
2023-06-25 20:20:59 -06:00
|
|
|
if err != nil {
|
|
|
|
ctx.Log.Logf("gqlws", "type convertor error %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c <- ret
|
|
|
|
}
|
|
|
|
}(c, server)
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2023-07-03 18:58:15 -06:00
|
|
|
var gql_subscription_self * graphql.Field = nil
|
|
|
|
func GQLSubscriptionSelf() * graphql.Field {
|
|
|
|
if gql_subscription_self == nil {
|
|
|
|
gql_subscription_self = &graphql.Field{
|
|
|
|
Type: GQLTypeGQLThread(),
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return p.Source, nil
|
|
|
|
},
|
|
|
|
Subscribe: GQLSubscribeSelf,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 19:04:51 -06:00
|
|
|
return gql_subscription_self
|
2023-07-03 18:58:15 -06:00
|
|
|
}
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
var gql_subscription_update * graphql.Field = nil
|
|
|
|
func GQLSubscriptionUpdate() * graphql.Field {
|
|
|
|
if gql_subscription_update == nil {
|
|
|
|
gql_subscription_update = &graphql.Field{
|
|
|
|
Type: GQLTypeSignal(),
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
return p.Source, nil
|
|
|
|
},
|
|
|
|
Subscribe: GQLSubscribeSignal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gql_subscription_update
|
|
|
|
}
|
|
|
|
|
2023-07-21 14:28:53 -06:00
|
|
|
func PrepResolve(p graphql.ResolveParams) (*Context, *GQLThread, *User, error) {
|
|
|
|
context, ok := p.Context.Value("graph_context").(*Context)
|
|
|
|
if ok == false {
|
|
|
|
return nil, nil, nil, fmt.Errorf("failed to cast graph_context to *Context")
|
|
|
|
}
|
|
|
|
|
|
|
|
server, ok := p.Context.Value("gql_server").(*GQLThread)
|
|
|
|
if ok == false {
|
|
|
|
return nil, nil, nil, fmt.Errorf("failed to cast gql_server to *GQLThread")
|
|
|
|
}
|
|
|
|
|
|
|
|
user, ok := p.Context.Value("user").(*User)
|
|
|
|
if ok == false {
|
|
|
|
return nil, nil, nil, fmt.Errorf("failed to cast user to *User")
|
|
|
|
}
|
|
|
|
|
|
|
|
return context, server, user, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExtractParam[K interface{}](p graphql.ResolveParams, name string) (K, error) {
|
|
|
|
var zero K
|
|
|
|
arg_if, ok := p.Args[name]
|
|
|
|
if ok == false {
|
|
|
|
return zero, fmt.Errorf("No Arg of name %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
arg, ok := arg_if.(K)
|
|
|
|
if ok == false {
|
|
|
|
return zero, fmt.Errorf("Failed to cast arg %s(%+v) to %+v", name, arg_if, reflect.TypeOf(zero))
|
|
|
|
}
|
|
|
|
|
|
|
|
return arg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExtractID(p graphql.ResolveParams, name string) (NodeID, error) {
|
|
|
|
id_str, err := ExtractParam[string](p, name)
|
|
|
|
if err != nil {
|
|
|
|
return ZeroID, err
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := ParseID(id_str)
|
|
|
|
if err != nil {
|
|
|
|
return ZeroID, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
var gql_mutation_send_update *graphql.Field = nil
|
|
|
|
func GQLMutationSendUpdate() *graphql.Field {
|
|
|
|
if gql_mutation_send_update == nil {
|
|
|
|
gql_mutation_send_update = &graphql.Field{
|
|
|
|
Type: GQLTypeSignal(),
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
"id": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
"signal": &graphql.ArgumentConfig{
|
|
|
|
Type: GQLTypeSignalInput(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-21 14:28:53 -06:00
|
|
|
ctx, server, user, err := PrepResolve(p)
|
2023-07-21 12:09:29 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-21 13:34:47 -06:00
|
|
|
err = server.Allowed("signal", "self", user)
|
2023-07-21 12:09:29 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
2023-07-21 14:28:53 -06:00
|
|
|
signal_map, err := ExtractParam[map[string]interface{}](p, "signal")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
2023-07-21 14:28:53 -06:00
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
var signal GraphSignal = nil
|
2023-06-25 21:00:00 -06:00
|
|
|
if signal_map["Direction"] == "up" {
|
2023-06-25 20:20:59 -06:00
|
|
|
signal = NewSignal(server, signal_map["Type"].(string))
|
2023-06-25 21:00:00 -06:00
|
|
|
} else if signal_map["Direction"] == "down" {
|
2023-06-25 20:20:59 -06:00
|
|
|
signal = NewDownSignal(server, signal_map["Type"].(string))
|
2023-06-25 21:00:00 -06:00
|
|
|
} else if signal_map["Direction"] == "direct" {
|
2023-06-25 20:20:59 -06:00
|
|
|
signal = NewDirectSignal(server, signal_map["Type"].(string))
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("Bad direction: %d", signal_map["Direction"])
|
|
|
|
}
|
|
|
|
|
2023-07-21 14:28:53 -06:00
|
|
|
id, err := ExtractID(p, "id")
|
2023-07-19 20:03:13 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:30:19 -06:00
|
|
|
var node Node = nil
|
2023-07-19 20:03:13 -06:00
|
|
|
err = UseStates(ctx, []Node{server}, func(nodes NodeMap) (error){
|
|
|
|
node = FindChild(ctx, server, id, nodes)
|
2023-06-25 20:20:59 -06:00
|
|
|
if node == nil {
|
2023-06-28 00:48:49 -06:00
|
|
|
return fmt.Errorf("Failed to find ID: %s as child of server thread", id)
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
2023-07-09 20:30:19 -06:00
|
|
|
node.Signal(ctx, signal, nodes)
|
2023-06-28 00:48:49 -06:00
|
|
|
return nil
|
2023-06-25 20:20:59 -06:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return signal, nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gql_mutation_send_update
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:59:52 -06:00
|
|
|
var gql_mutation_start_child *graphql.Field = nil
|
|
|
|
func GQLMutationStartChild() *graphql.Field {
|
|
|
|
if gql_mutation_start_child == nil {
|
|
|
|
gql_mutation_start_child = &graphql.Field{
|
|
|
|
Type: GQLTypeSignal(),
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
"parent_id": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
"child_id": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
"action": &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
DefaultValue: "start",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-21 14:28:53 -06:00
|
|
|
ctx, server, user, err := PrepResolve(p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-07-21 13:59:52 -06:00
|
|
|
}
|
|
|
|
|
2023-07-21 14:28:53 -06:00
|
|
|
err = server.Allowed("start_child", "self", user)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-07-21 13:59:52 -06:00
|
|
|
}
|
|
|
|
|
2023-07-21 14:28:53 -06:00
|
|
|
parent_id, err := ExtractID(p, "parent_id")
|
2023-07-21 13:59:52 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-21 14:28:53 -06:00
|
|
|
child_id, err := ExtractID(p, "child_id")
|
2023-07-21 13:59:52 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-21 14:28:53 -06:00
|
|
|
action, err := ExtractParam[string](p, "action")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-07-21 13:59:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var signal GraphSignal
|
|
|
|
err = UseStates(ctx, []Node{server}, func(nodes NodeMap) (error){
|
|
|
|
node := FindChild(ctx, server, parent_id, nodes)
|
|
|
|
if node == nil {
|
|
|
|
return fmt.Errorf("Failed to find ID: %s as child of server thread", parent_id)
|
|
|
|
}
|
|
|
|
return UseMoreStates(ctx, []Node{node}, nodes, func(NodeMap) error {
|
|
|
|
signal = NewStartChildSignal(server, child_id, action)
|
|
|
|
return node.Signal(ctx, signal, nodes)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: wait for the result of the signal to send back instead of just the signal
|
|
|
|
return signal, nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gql_mutation_start_child
|
|
|
|
}
|
|
|
|
|
2023-06-25 20:20:59 -06:00
|
|
|
var gql_query_self *graphql.Field = nil
|
|
|
|
func GQLQuerySelf() *graphql.Field {
|
|
|
|
if gql_query_self == nil {
|
|
|
|
gql_query_self = &graphql.Field{
|
|
|
|
Type: GQLTypeGQLThread(),
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2023-07-21 14:28:53 -06:00
|
|
|
_, server, user, err := PrepResolve(p)
|
2023-07-21 12:09:29 -06:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:34:47 -06:00
|
|
|
err = server.Allowed("enumerate", "self", user)
|
2023-07-21 12:09:29 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("User %s is not allowed to perform self.enumerate on %s", user.ID(), server.ID())
|
2023-06-25 20:20:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return server, nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gql_query_self
|
|
|
|
}
|