|
|
|
@ -2,6 +2,7 @@ package graphvent
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
graphql "github.com/graphql-go/graphql"
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"reflect"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
@ -37,7 +38,7 @@ var type_gql_map = map[reflect.Type]GQLTypeInfo{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if str == "" {
|
|
|
|
|
return reflect.New(reflect.TypeOf(NodeID{})), nil
|
|
|
|
|
return reflect.New(reflect.TypeOf(&NodeID{})).Elem(), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id_parsed, err := ParseID(str)
|
|
|
|
@ -73,8 +74,15 @@ type StructFieldInfo struct {
|
|
|
|
|
Index []int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SignalFromArgs(signal_type reflect.Type, fields []StructFieldInfo, args map[string]interface{}) (Signal, error) {
|
|
|
|
|
func SignalFromArgs(signal_type reflect.Type, fields []StructFieldInfo, args map[string]interface{}, id_index, direction_index []int) (Signal, error) {
|
|
|
|
|
signal_value := reflect.New(signal_type)
|
|
|
|
|
|
|
|
|
|
id_field := signal_value.Elem().FieldByIndex(id_index)
|
|
|
|
|
id_field.Set(reflect.ValueOf(uuid.New()))
|
|
|
|
|
|
|
|
|
|
direction_field := signal_value.Elem().FieldByIndex(direction_index)
|
|
|
|
|
direction_field.Set(reflect.ValueOf(Direct))
|
|
|
|
|
|
|
|
|
|
for _, field := range(fields) {
|
|
|
|
|
arg, arg_exists := args[field.Name]
|
|
|
|
|
if arg_exists == false {
|
|
|
|
@ -96,16 +104,17 @@ func SignalFromArgs(signal_type reflect.Type, fields []StructFieldInfo, args map
|
|
|
|
|
func (ext *GQLExtContext) AddSignalMutation(name string, send_id_key string, signal_type reflect.Type) error {
|
|
|
|
|
args := graphql.FieldConfigArgument{}
|
|
|
|
|
arg_info := []StructFieldInfo{}
|
|
|
|
|
var id_index []int = nil
|
|
|
|
|
var direction_index []int = nil
|
|
|
|
|
|
|
|
|
|
for _, field := range(reflect.VisibleFields(signal_type)) {
|
|
|
|
|
gv_tag, tagged_gv := field.Tag.Lookup("gv")
|
|
|
|
|
if tagged_gv {
|
|
|
|
|
if gv_tag == "id" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if gv_tag == "direction" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
id_index = field.Index
|
|
|
|
|
} else if gv_tag == "direction" {
|
|
|
|
|
direction_index = field.Index
|
|
|
|
|
} else {
|
|
|
|
|
_, exists := args[gv_tag]
|
|
|
|
|
if exists == true {
|
|
|
|
|
return fmt.Errorf("Signal has repeated tag %s", gv_tag)
|
|
|
|
@ -132,6 +141,7 @@ func (ext *GQLExtContext) AddSignalMutation(name string, send_id_key string, sig
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, send_exists := args[send_id_key]
|
|
|
|
|
if send_exists == false {
|
|
|
|
@ -151,7 +161,7 @@ func (ext *GQLExtContext) AddSignalMutation(name string, send_id_key string, sig
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
signal, err := SignalFromArgs(signal_type, arg_info, p.Args)
|
|
|
|
|
signal, err := SignalFromArgs(signal_type, arg_info, p.Args, id_index, direction_index)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|