38 lines
861 B
Go
38 lines
861 B
Go
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 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
|
|
}
|