From c3db875a5fe14451b52576a6a5d09c623b826c40 Mon Sep 17 00:00:00 2001 From: yssk22 Date: Wed, 25 Oct 2023 04:31:02 +0000 Subject: [PATCH] [go][graphql] fix node(id:ID) interface **Summary** now we accept "helloproject" as an ID of Node, the code should check the value before passing it to ent.Noder() **Test** - go test **Issue** - N/A --- go/graphql/v3/resolver/resolver.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/go/graphql/v3/resolver/resolver.go b/go/graphql/v3/resolver/resolver.go index d433d20d..cbfe9428 100644 --- a/go/graphql/v3/resolver/resolver.go +++ b/go/graphql/v3/resolver/resolver.go @@ -2,6 +2,7 @@ package resolver import ( "context" + "fmt" "strconv" "github.com/yssk22/hpapp/go/foundation/slice" @@ -16,21 +17,21 @@ import ( type Resolver struct{} func (r *queryResolver) Node(ctx context.Context, id string) (ent.Noder, error) { + if id == "helloproject" { + return &helloproject.HelloProjectQuery{}, nil + } entid, err := strconv.Atoi(id) if err != nil { - return nil, err + return nil, fmt.Errorf("not a valid node id") } return entutil.NewClient(ctx).Noder(ctx, entid) } +// TODO: this might cause the performance issue if a client requests too many id func (r *queryResolver) Nodes(ctx context.Context, ids []string) ([]ent.Noder, error) { - entids, err := slice.Map(ids, func(_ int, id string) (int, error) { - return strconv.Atoi(id) + return slice.Map(ids, func(_ int, id string) (ent.Noder, error) { + return r.Node(ctx, id) }) - if err != nil { - return nil, err - } - return entutil.NewClient(ctx).Noders(ctx, entids) } func (r *queryResolver) Helloproject(ctx context.Context) (*helloproject.HelloProjectQuery, error) {