From f56f92a58be9739f4810251f215ee58dc5334e2b Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sat, 29 Jul 2023 23:24:48 -0600 Subject: [PATCH] Updated test with group ext gql --- gql.go | 31 ++++++++++++++++++++++++++++++- gql_test.go | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gql.go b/gql.go index 7d56e0f..fd3d144 100644 --- a/gql.go +++ b/gql.go @@ -791,6 +791,35 @@ func NewGQLExtContext() *GQLExtContext { panic(err) } + err = RegisterField(&context, context.Interfaces["Node"].List, "Members", GroupExtType, "members", + func(p graphql.ResolveParams, val map[NodeID]string)(interface{}, error) { + ctx, err := PrepResolve(p) + if err != nil { + return nil, err + } + node_list := make([]NodeID, len(val)) + i := 0 + for id, _ := range(val) { + node_list[i] = id + i += 1 + } + + nodes, err := ResolveNodes(ctx, p, node_list) + if err != nil { + return nil, err + } + + return nodes, nil + }) + if err != nil { + panic(err) + } + + err = context.RegisterInterface("Group", "DefaultGroup", []string{"Node"}, []string{"Members"}, map[string]SelfField{}, map[string]ListField{}) + if err != nil { + panic(err) + } + err = context.RegisterInterface("Lockable", "DefaultLockable", []string{"Node"}, []string{}, map[string]SelfField{ "Owner": SelfField{ "owner", @@ -860,7 +889,7 @@ func NewGQLExtContext() *GQLExtContext { panic(err) } - err = context.RegisterNodeType(GQLNodeType, "GQLServer", []string{"Node", "Lockable"}, []string{"Listen", "Owner", "Requirements", "Dependencies"}) + err = context.RegisterNodeType(GQLNodeType, "GQLServer", []string{"Node", "Lockable", "Group"}, []string{"Listen", "Owner", "Requirements", "Dependencies", "Members"}) if err != nil { panic(err) } diff --git a/gql_test.go b/gql_test.go index 31127ec..5629b7c 100644 --- a/gql_test.go +++ b/gql_test.go @@ -55,7 +55,7 @@ func TestGQL(t *testing.T) { } req_2 := GQLPayload{ - Query: "query Node($id:String) { Node(id:$id) { ID, TypeHash, ... on GQLServer { Listen, Requirements { ID, TypeHash, Dependencies { ID } } } } }", + Query: "query Node($id:String) { Node(id:$id) { ID, TypeHash, ... on GQLServer { Members { ID } , Listen, Requirements { ID, TypeHash, Dependencies { ID } } } } }", Variables: map[string]interface{}{ "id": gql.ID.String(), },