Skip to content

Commit

Permalink
fix: add gql marshal functions for wrappedmap
Browse files Browse the repository at this point in the history
Signed-off-by: David van der Spek <[email protected]>
  • Loading branch information
davidspek committed Jul 14, 2023
1 parent d7dbdaa commit 1991a1b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/observability/v1alpha1/tempo_limit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1991a1b

Please sign in to comment.