2023-07-21 15:16:35 -06:00
|
|
|
package graphvent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
)
|
|
|
|
|
2023-07-26 23:57:50 -06:00
|
|
|
func AddNodeFields(object *graphql.Object) {
|
|
|
|
object.AddFieldConfig("ID", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
2023-07-29 16:00:01 -06:00
|
|
|
Resolve: ResolveNodeID,
|
2023-07-26 23:57:50 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
object.AddFieldConfig("TypeHash", &graphql.Field{
|
|
|
|
Type: graphql.String,
|
2023-07-29 16:00:01 -06:00
|
|
|
Resolve: ResolveNodeTypeHash,
|
2023-07-26 23:57:50 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-29 17:23:25 -06:00
|
|
|
var NodeInterfaces = []*Interface{InterfaceNode}
|
|
|
|
var LockableInterfaces = append(NodeInterfaces, InterfaceLockable)
|
2023-07-26 23:57:50 -06:00
|
|
|
|
2023-07-29 17:23:25 -06:00
|
|
|
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{},
|
2023-07-26 23:57:50 -06:00
|
|
|
})
|
2023-07-29 17:23:25 -06:00
|
|
|
gql.List = graphql.NewList(gql.Type)
|
2023-07-26 23:57:50 -06:00
|
|
|
|
2023-07-29 17:23:25 -06:00
|
|
|
init(&gql)
|
|
|
|
return &gql
|
2023-07-26 23:57:50 -06:00
|
|
|
}
|
|
|
|
|
2023-07-29 11:03:41 -06:00
|
|
|
var TypeSignal = NewSingleton(func() *graphql.Object {
|
2023-07-21 17:49:19 -06:00
|
|
|
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 {
|
2023-07-26 15:08:14 -06:00
|
|
|
_, ok := p.Value.(Signal)
|
2023-07-21 17:49:19 -06:00
|
|
|
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)
|
|
|
|
|