graphvent/gql_types.go

67 lines
1.6 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,
})
}
var NodeInterfaces = []*Interface{InterfaceNode}
var LockableInterfaces = append(NodeInterfaces, InterfaceLockable)
func NewGQLNodeType(node_type NodeType, interfaces []*graphql.Interface, init func(*Type)) *Type {
var gql Type
gql.Type = graphql.NewObject(graphql.ObjectConfig{
Name: string(node_type),
Interfaces: interfaces,
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
node, ok := p.Value.(NodeResult)
if ok == false {
return false
}
return node.Result.NodeType == node_type
},
Fields: graphql.Fields{},
})
gql.List = graphql.NewList(gql.Type)
init(&gql)
return &gql
}
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)