From 1991a1b7014b94aca147a5aa7d778f75e09901a7 Mon Sep 17 00:00:00 2001 From: David van der Spek Date: Fri, 14 Jul 2023 14:39:05 +0200 Subject: [PATCH] fix: add gql marshal functions for wrappedmap Signed-off-by: David van der Spek --- api/observability/v1alpha1/tempo_limit_types.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/observability/v1alpha1/tempo_limit_types.go b/api/observability/v1alpha1/tempo_limit_types.go index 3138542..dc196b5 100644 --- a/api/observability/v1alpha1/tempo_limit_types.go +++ b/api/observability/v1alpha1/tempo_limit_types.go @@ -183,6 +183,21 @@ type WrappedMap struct { Object map[string]interface{} `yaml:",inline" json:",inline"` } +func (e *WrappedMap) UnmarshalGQL(v interface{}) error { + m, ok := v.(map[string]interface{}) + if !ok { + return fmt.Errorf("%T is not a map", v) + } + + *e = WrappedMap{Object: m} + + return nil +} + +func (e WrappedMap) MarshalGQL(w io.Writer) { + json.NewEncoder(w).Encode(e) +} + // MarshalJSON defers JSON encoding to the wrapped map func (w *WrappedMap) MarshalJSON() ([]byte, error) { return json.Marshal(w.Object)