2023-07-21 15:16:35 -06:00
|
|
|
package graphvent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
)
|
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
func AddNodeFields(obj *graphql.Object) {
|
|
|
|
obj.AddFieldConfig("ID", &graphql.Field{
|
2023-07-21 17:49:19 -06:00
|
|
|
Type: graphql.String,
|
2023-07-21 18:06:53 -06:00
|
|
|
Resolve: GQLNodeID,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
2023-07-21 18:06:53 -06:00
|
|
|
}
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
func AddLockableFields(obj *graphql.Object) {
|
|
|
|
AddNodeFields(obj)
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
obj.AddFieldConfig("Name", &graphql.Field{
|
2023-07-21 17:49:19 -06:00
|
|
|
Type: graphql.String,
|
2023-07-21 18:06:53 -06:00
|
|
|
Resolve: GQLLockableName,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
obj.AddFieldConfig("Requirements", &graphql.Field{
|
2023-07-21 17:49:19 -06:00
|
|
|
Type: GQLInterfaceLockable.List,
|
2023-07-21 18:06:53 -06:00
|
|
|
Resolve: GQLLockableRequirements,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
obj.AddFieldConfig("Owner", &graphql.Field{
|
2023-07-21 17:49:19 -06:00
|
|
|
Type: GQLInterfaceLockable.Type,
|
2023-07-21 18:06:53 -06:00
|
|
|
Resolve: GQLLockableOwner,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
obj.AddFieldConfig("Dependencies", &graphql.Field{
|
|
|
|
Type: GQLInterfaceLockable.List,
|
|
|
|
Resolve: GQLLockableDependencies,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
2023-07-21 18:06:53 -06:00
|
|
|
}
|
2023-07-21 17:49:19 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
func AddThreadFields(obj *graphql.Object) {
|
|
|
|
AddLockableFields(obj)
|
2023-07-21 17:49:19 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
obj.AddFieldConfig("State", &graphql.Field{
|
2023-07-21 17:49:19 -06:00
|
|
|
Type: graphql.String,
|
2023-07-21 18:06:53 -06:00
|
|
|
Resolve: GQLThreadState,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
obj.AddFieldConfig("Children", &graphql.Field{
|
|
|
|
Type: GQLInterfaceThread.List,
|
|
|
|
Resolve: GQLThreadChildren,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
obj.AddFieldConfig("Parent", &graphql.Field{
|
|
|
|
Type: GQLInterfaceThread.Type,
|
|
|
|
Resolve: GQLThreadParent,
|
2023-07-21 17:49:19 -06:00
|
|
|
})
|
2023-07-21 18:06:53 -06:00
|
|
|
}
|
2023-07-21 17:49:19 -06:00
|
|
|
|
|
|
|
var GQLTypeUser = NewSingleton(func() *graphql.Object {
|
|
|
|
gql_type_user := graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "User",
|
|
|
|
Interfaces: []*graphql.Interface{
|
|
|
|
GQLInterfaceNode.Type,
|
|
|
|
GQLInterfaceLockable.Type,
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
2023-07-21 18:09:13 -06:00
|
|
|
_, ok := p.Value.(*User)
|
|
|
|
return ok
|
2023-07-21 17:49:19 -06:00
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
AddLockableFields(gql_type_user)
|
2023-07-21 17:49:19 -06:00
|
|
|
|
2023-07-21 15:16:35 -06:00
|
|
|
return gql_type_user
|
2023-07-21 17:49:19 -06:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
var GQLTypeGQLThread = NewSingleton(func() *graphql.Object {
|
|
|
|
gql_type_gql_thread := graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "GQLThread",
|
|
|
|
Interfaces: []*graphql.Interface{
|
|
|
|
GQLInterfaceNode.Type,
|
|
|
|
GQLInterfaceThread.Type,
|
|
|
|
GQLInterfaceLockable.Type,
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
|
|
|
_, ok := p.Value.(*GQLThread)
|
|
|
|
return ok
|
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
AddThreadFields(gql_type_gql_thread)
|
2023-07-21 17:49:19 -06:00
|
|
|
|
|
|
|
gql_type_gql_thread.AddFieldConfig("Users", &graphql.Field{
|
|
|
|
Type: GQLTypeUser.List,
|
|
|
|
Resolve: GQLThreadUsers,
|
|
|
|
})
|
2023-07-21 18:06:53 -06:00
|
|
|
|
2023-07-21 18:07:49 -06:00
|
|
|
gql_type_gql_thread.AddFieldConfig("Listen", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLThreadListen,
|
|
|
|
})
|
|
|
|
|
2023-07-21 15:16:35 -06:00
|
|
|
return gql_type_gql_thread
|
2023-07-21 17:49:19 -06:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
var GQLTypeSimpleThread = NewSingleton(func() *graphql.Object {
|
|
|
|
gql_type_simple_thread := graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "SimpleThread",
|
|
|
|
Interfaces: []*graphql.Interface{
|
|
|
|
GQLInterfaceNode.Type,
|
|
|
|
GQLInterfaceThread.Type,
|
|
|
|
GQLInterfaceLockable.Type,
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
2023-07-21 18:18:26 -06:00
|
|
|
_, ok := p.Value.(Thread)
|
|
|
|
return ok
|
2023-07-21 17:49:19 -06:00
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
AddThreadFields(gql_type_simple_thread)
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 17:49:19 -06:00
|
|
|
return gql_type_simple_thread
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
var GQLTypeSimpleLockable = NewSingleton(func() *graphql.Object {
|
|
|
|
gql_type_simple_lockable := graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: "SimpleLockable",
|
|
|
|
Interfaces: []*graphql.Interface{
|
|
|
|
GQLInterfaceNode.Type,
|
|
|
|
GQLInterfaceLockable.Type,
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
2023-07-21 18:18:26 -06:00
|
|
|
_, ok := p.Value.(Lockable)
|
|
|
|
return ok
|
2023-07-21 17:49:19 -06:00
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
AddLockableFields(gql_type_simple_lockable)
|
2023-07-21 15:16:35 -06:00
|
|
|
|
2023-07-21 17:49:19 -06:00
|
|
|
return gql_type_simple_lockable
|
|
|
|
}, nil)
|
|
|
|
|
2023-07-24 16:04:56 -06:00
|
|
|
var GQLTypeSimpleNode = NewSingleton(func() *graphql.Object {
|
2023-07-21 17:49:19 -06:00
|
|
|
object := graphql.NewObject(graphql.ObjectConfig{
|
2023-07-24 16:04:56 -06:00
|
|
|
Name: "SimpleNode",
|
2023-07-21 17:49:19 -06:00
|
|
|
Interfaces: []*graphql.Interface{
|
|
|
|
GQLInterfaceNode.Type,
|
|
|
|
},
|
|
|
|
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
|
2023-07-21 18:18:26 -06:00
|
|
|
_, ok := p.Value.(Node)
|
|
|
|
return ok
|
2023-07-21 17:49:19 -06:00
|
|
|
},
|
|
|
|
Fields: graphql.Fields{},
|
|
|
|
})
|
|
|
|
|
2023-07-21 18:06:53 -06:00
|
|
|
AddNodeFields(object)
|
2023-07-21 17:49:19 -06:00
|
|
|
|
|
|
|
return object
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
var GQLTypeSignal = NewSingleton(func() *graphql.Object {
|
|
|
|
gql_type_signal := graphql.NewObject(graphql.ObjectConfig{
|
2023-07-22 20:21:17 -06:00
|
|
|
Name: "Signal",
|
2023-07-21 17:49:19 -06:00
|
|
|
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("Direction", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLSignalDirection,
|
|
|
|
})
|
|
|
|
gql_type_signal.AddFieldConfig("String", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
Resolve: GQLSignalString,
|
|
|
|
})
|
2023-07-21 15:16:35 -06:00
|
|
|
return gql_type_signal
|
2023-07-21 17:49:19 -06:00
|
|
|
}, nil)
|
|
|
|
|