Added more signal string representations, and fixed event/gql bugs

gql_cataclysm
noah metz 2023-11-01 19:32:36 -06:00
parent a061d6850c
commit 3a6e562390
4 changed files with 29 additions and 10 deletions

@ -78,7 +78,7 @@ func (ext *EventExt) Process(ctx *Context, node *Node, source NodeID, signal Sig
type TestEventExt struct {}
var transitions = map[string]struct{
var test_event_transitions = map[string]struct{
from_state string
to_state string
}{
@ -107,9 +107,10 @@ func (ext *TestEventExt) Process(ctx *Context, node *Node, source NodeID, signal
if err != nil {
messages = messages.Add(ctx, source, node, nil, NewErrorSignal(sig.Id, "not_event"))
} else {
info, exists := transitions[sig.Command]
info, exists := test_event_transitions[sig.Command]
if exists == true {
if event_ext.State == info.from_state {
ctx.Log.Logf("event", "%s %s->%s", node.ID, info.from_state, info.to_state)
event_ext.State = info.to_state
messages = messages.Add(ctx, source, node, nil, NewSuccessSignal(sig.Id))
node.QueueSignal(time.Now(), NewEventStateSignal(node.ID, event_ext.State, time.Now()))

@ -604,7 +604,7 @@ func GQLHandler(ctx *Context, server *Node, gql_ext *GQLExt) func(http.ResponseW
extra_fields := map[string]interface{}{}
extra_fields["body"] = string(str)
extra_fields["headers"] = r.Header
ctx.Log.Logm("gql", extra_fields, "wrong result, unexpected errors: %v", result.Errors)
ctx.Log.Logm("gql_errors", extra_fields, "wrong result, unexpected errors: %v", result.Errors)
}
json.NewEncoder(w).Encode(result)
}
@ -773,7 +773,7 @@ func GQLWSHandler(ctx * Context, server *Node, gql_ext *GQLExt) func(http.Respon
if len(next.Errors) > 0 {
extra_fields := map[string]interface{}{}
extra_fields["query"] = string(msg.Payload.Query)
ctx.Log.Logm("gqlws", extra_fields, "ERROR: wrong result, unexpected errors: %+v", next.Errors)
ctx.Log.Logm("gql_errors", extra_fields, "ERROR: wrong result, unexpected errors: %+v", next.Errors)
continue
}
ctx.Log.Logf("gqlws", "DATA: %+v", next.Data)
@ -912,7 +912,7 @@ func (ctx *GQLExtContext) RegisterField(gql_type graphql.Type, gql_name string,
ext, ext_exists := node.Data[ext_type]
if ext_exists == false {
return nil, fmt.Errorf("%+v is not in the extensions of the result", ext_type)
return nil, fmt.Errorf("%+v is not in the extensions of the result: %+v", ext_type, node.Data)
}
val_ser, field_exists := ext[gv_tag]

@ -129,11 +129,17 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
errors := ""
for sig_id, response_chan := range(resp_channels) {
// Wait for the response, returning an error on timeout
response, _, err := WaitForResponse(response_chan, time.Millisecond*100, sig_id)
response, other, err := WaitForResponse(response_chan, time.Millisecond*100, sig_id)
if err != nil {
return nil, err
}
ctx.Context.Log.Logf("gql_resolve_node", "GQL node response: %+v", response)
ctx.Context.Log.Logf("gql_resolve_node", "GQL node other messages: %+v", other)
// for now, just put signals we didn't want back into the 'queue'
for _, other_signal := range(other) {
response_chan <- other_signal
}
error_signal, is_error := response.(*ErrorSignal)
if is_error {
@ -159,10 +165,12 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
ctx.Context.Log.Logf("gql_resolve_node", "Merging new response with cached: %s, %+v - %+v", read_response.NodeID, cache, read_response.Extensions)
for ext_type, fields := range(read_response.Extensions) {
cached_fields, exists := cache.Data[ext_type]
if exists == true {
for field_name, field_value := range(fields) {
cached_fields[field_name] = field_value
}
if exists == false {
cached_fields = map[string]SerializedValue{}
cache.Data[ext_type] = cached_fields
}
for field_name, field_value := range(fields) {
cached_fields[field_name] = field_value
}
}
responses[idx] = cache

@ -331,6 +331,10 @@ type ReadSignal struct {
Extensions map[ExtType][]string `json:"extensions"`
}
func (signal ReadSignal) String() string {
return fmt.Sprintf("ReadSignal(%s, %+v)", signal.SignalHeader, signal.Extensions)
}
func (signal ReadSignal) Permission() Tree {
ret := Tree{}
for ext, fields := range(signal.Extensions) {
@ -342,6 +346,7 @@ func (signal ReadSignal) Permission() Tree {
}
return Tree{SerializedType(ReadSignalType): ret}
}
func NewReadSignal(exts map[ExtType][]string) *ReadSignal {
return &ReadSignal{
NewSignalHeader(Direct),
@ -355,6 +360,11 @@ type ReadResultSignal struct {
NodeType NodeType
Extensions map[ExtType]map[string]SerializedValue
}
func (signal ReadResultSignal) String() string {
return fmt.Sprintf("ReadResultSignal(%s, %s, %+v, %+v)", signal.SignalHeader, signal.NodeID, signal.NodeType, signal.Extensions)
}
func (signal ReadResultSignal) Permission() Tree {
return Tree{
ResponseType: {