graphvent/gql_types.go

78 lines
2.0 KiB
Go

2023-07-21 15:16:35 -06:00
package graphvent
import (
"github.com/graphql-go/graphql"
)
func AddNodeFields(object *graphql.Object) {
object.AddFieldConfig("ID", &graphql.Field{
Type: graphql.String,
Resolve: ResolveNodeID,
})
object.AddFieldConfig("TypeHash", &graphql.Field{
Type: graphql.String,
Resolve: ResolveNodeTypeHash,
})
}
func AddLockableFields(object *graphql.Object) {
2023-07-29 11:03:41 -06:00
addLockableFields(object, InterfaceLockable.Interface, InterfaceLockable.List)
}
func addLockableFields(object *graphql.Object, lockable_interface *graphql.Interface, lockable_list *graphql.List) {
AddNodeFields(object)
object.AddFieldConfig("Requirements", &graphql.Field{
Type: lockable_list,
Resolve: ResolveRequirements,
})
object.AddFieldConfig("Owner", &graphql.Field{
Type: lockable_interface,
Resolve: ResolveOwner,
})
object.AddFieldConfig("Dependencies", &graphql.Field{
Type: lockable_list,
Resolve: ResolveDependencies,
})
}
2023-07-29 11:03:41 -06:00
var GQLNodeInterfaces = []*graphql.Interface{InterfaceNode.Interface}
var GQLLockableInterfaces = append(GQLNodeInterfaces, InterfaceLockable.Interface)
2023-07-29 11:03:41 -06:00
var TypeGQLNode = NewGQLNodeType(GQLNodeType, GQLNodeInterfaces, func(gql *Type) {
AddNodeFields(gql.Type)
2023-07-27 00:30:24 -06:00
gql.Type.AddFieldConfig("Listen", &graphql.Field{
Type: graphql.String,
Resolve: ResolveListen,
2023-07-27 00:30:24 -06:00
})
})
2023-07-29 11:03:41 -06:00
var TypeSignal = NewSingleton(func() *graphql.Object {
gql_type_signal := graphql.NewObject(graphql.ObjectConfig{
Name: "Signal",
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
_, ok := p.Value.(Signal)
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
}, nil)