Updated gql test with working subscribe

gql_cataclysm
noah metz 2023-10-11 19:04:43 -06:00
parent ae289705bb
commit b32f264879
2 changed files with 18 additions and 13 deletions

@ -1098,15 +1098,9 @@ func NewGQLExtContext() *GQLExtContext {
err = context.RegisterField(context.Interfaces["Node"].List, "Members", GroupExtType, "members", err = context.RegisterField(context.Interfaces["Node"].List, "Members", GroupExtType, "members",
func(p graphql.ResolveParams, ctx *ResolveContext, value reflect.Value)(interface{}, error) { func(p graphql.ResolveParams, ctx *ResolveContext, value reflect.Value)(interface{}, error) {
node_map, ok := value.Interface().(map[NodeID]string) node_list, ok := value.Interface().([]NodeID)
if ok == false { if ok == false {
return nil, fmt.Errorf("value is %+v, not map[NodeID]string", value.Type()) return nil, fmt.Errorf("value is %+v, not []NodeID", value.Type())
}
node_list := []NodeID{}
i := 0
for id := range(node_map) {
node_list = append(node_list, id)
i += 1
} }
nodes, err := ResolveNodes(ctx, p, node_list) nodes, err := ResolveNodes(ctx, p, node_list)

@ -19,7 +19,7 @@ import (
) )
func TestGQLServer(t *testing.T) { func TestGQLServer(t *testing.T) {
ctx := logTestContext(t, []string{"test"}) ctx := logTestContext(t, []string{"test", "gqlws"})
TestNodeType := NewNodeType("TEST") TestNodeType := NewNodeType("TEST")
err := ctx.RegisterNodeType(TestNodeType, []ExtType{LockableExtType}) err := ctx.RegisterNodeType(TestNodeType, []ExtType{LockableExtType})
@ -135,7 +135,7 @@ func TestGQLServer(t *testing.T) {
ctx.Log.Logf("test", "RESP_2: %s", resp_2) ctx.Log.Logf("test", "RESP_2: %s", resp_2)
sub_1 := GQLPayload{ sub_1 := GQLPayload{
Query: "subscription { Self { ID, TypeHash, Requirements { ID }}}", Query: "subscription { Self { ID, TypeHash, ... on Lockable { Requirements { ID }}}}",
} }
SubGQL := func(payload GQLPayload) { SubGQL := func(payload GQLPayload) {
@ -149,9 +149,18 @@ func TestGQLServer(t *testing.T) {
fatalErr(t, err) fatalErr(t, err)
init := GQLWSMsg{ type payload_struct struct {
ID: uuid.New().String(), Token string `json:"token"`
Type: "connection_init", }
init := struct{
ID uuid.UUID `json:"id"`
Type string `json:"type"`
Payload payload_struct `json:"payload"`
}{
uuid.New(),
"connection_init",
payload_struct{ auth_b64 },
} }
ser, err := json.Marshal(&init) ser, err := json.Marshal(&init)
@ -194,6 +203,8 @@ func TestGQLServer(t *testing.T) {
n, err = ws.Read(resp) n, err = ws.Read(resp)
fatalErr(t, err) fatalErr(t, err)
ctx.Log.Logf("test", "SUB: %s", resp[:n]) ctx.Log.Logf("test", "SUB: %s", resp[:n])
// TODO: check that there are no more messages sent to ws within a timeout
} }
SubGQL(sub_1) SubGQL(sub_1)