From dbf26a1ea6b48c9cd232b571a1c0b236079b01f5 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Tue, 31 Oct 2023 15:17:33 +0000 Subject: [PATCH] feat: support passing core type arrays to dagger call (#6030) * fix: always propagate error from marshalling Failing to marshal an argument should be preserved - if the caller discards the error, expecting it to fail later, the behaviour is very strange, and we get an empty string. Signed-off-by: Justin Chadwell * fix: marshal interface types as their element Signed-off-by: Justin Chadwell * feat: support passing core type arrays to dagger call Signed-off-by: Justin Chadwell --------- Signed-off-by: Justin Chadwell --- querybuilder/marshal.go | 2 +- querybuilder/querybuilder.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/querybuilder/marshal.go b/querybuilder/marshal.go index df013e5f8..2598bb1ed 100644 --- a/querybuilder/marshal.go +++ b/querybuilder/marshal.go @@ -66,7 +66,7 @@ func marshalValue(ctx context.Context, v reflect.Value) (string, error) { var buf bytes.Buffer gqlgen.MarshalString(v.String()).MarshalGQL(&buf) return buf.String(), nil //nolint:gosimple,staticcheck - case reflect.Pointer: + case reflect.Pointer, reflect.Interface: if v.IsNil() { return "null", nil } diff --git a/querybuilder/querybuilder.go b/querybuilder/querybuilder.go index 037bd98a5..c2841e513 100644 --- a/querybuilder/querybuilder.go +++ b/querybuilder/querybuilder.go @@ -168,15 +168,16 @@ func (s *Selection) Execute(ctx context.Context, c graphql.Client) error { } type argument struct { - value any - marshalled string - once sync.Once + value any + + marshalled string + marshalledErr error + once sync.Once } func (a *argument) marshal(ctx context.Context) error { - var err error a.once.Do(func() { - a.marshalled, err = MarshalGQL(ctx, a.value) + a.marshalled, a.marshalledErr = MarshalGQL(ctx, a.value) }) - return err + return a.marshalledErr }