55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package graphvent
|
|
import (
|
|
"reflect"
|
|
"fmt"
|
|
"github.com/graphql-go/graphql"
|
|
"github.com/graphql-go/graphql/language/ast"
|
|
)
|
|
|
|
func ResolveNodeID(p graphql.ResolveParams) (interface{}, error) {
|
|
node, ok := p.Source.(NodeResult)
|
|
if ok == false {
|
|
return nil, fmt.Errorf("Can't get NodeID from %+v", reflect.TypeOf(p.Source))
|
|
}
|
|
|
|
return node.NodeID, nil
|
|
}
|
|
|
|
func ResolveNodeTypeHash(p graphql.ResolveParams) (interface{}, error) {
|
|
node, ok := p.Source.(NodeResult)
|
|
if ok == false {
|
|
return nil, fmt.Errorf("Can't get TypeHash from %+v", reflect.TypeOf(p.Source))
|
|
}
|
|
|
|
return uint64(node.NodeType), nil
|
|
}
|
|
|
|
func GetFieldNames(ctx *Context, selection_set *ast.SelectionSet) []string {
|
|
names := []string{}
|
|
if selection_set == nil {
|
|
return names
|
|
}
|
|
|
|
for _, sel := range(selection_set.Selections) {
|
|
switch field := sel.(type) {
|
|
case *ast.Field:
|
|
names = append(names, field.Name.Value)
|
|
case *ast.InlineFragment:
|
|
names = append(names, GetFieldNames(ctx, field.SelectionSet)...)
|
|
default:
|
|
ctx.Log.Logf("gql", "Unknown selection type: %s", reflect.TypeOf(field))
|
|
}
|
|
}
|
|
|
|
return names
|
|
}
|
|
|
|
func GetResolveFields(ctx *Context, p graphql.ResolveParams) []string {
|
|
names := []string{}
|
|
for _, field := range(p.Info.FieldASTs) {
|
|
names = append(names, GetFieldNames(ctx, field.SelectionSet)...)
|
|
}
|
|
|
|
return names
|
|
}
|