github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/graphql/query_params.go (about) 1 package graphql 2 3 import ( 4 "encoding/json" 5 "io" 6 7 "github.com/kyma-incubator/compass/components/director/pkg/log" 8 9 "github.com/kyma-incubator/compass/components/director/pkg/apperrors" 10 "github.com/kyma-incubator/compass/components/director/pkg/scalar" 11 ) 12 13 // QueryParams missing godoc 14 type QueryParams map[string][]string 15 16 // UnmarshalGQL missing godoc 17 func (y *QueryParams) UnmarshalGQL(v interface{}) error { 18 params, err := scalar.ConvertToMapStringStringArray(v) 19 if err != nil { 20 return err 21 } 22 23 *y = params 24 25 return nil 26 } 27 28 // MarshalGQL missing godoc 29 func (y QueryParams) MarshalGQL(w io.Writer) { 30 err := scalar.WriteMarshalled(y, w) 31 if err != nil { 32 log.D().Errorf("while writing %T: %s", y, err) 33 return 34 } 35 } 36 37 // QueryParamsSerialized missing godoc 38 type QueryParamsSerialized string 39 40 // Unmarshal missing godoc 41 func (y *QueryParamsSerialized) Unmarshal() (map[string][]string, error) { 42 var data map[string][]string 43 if y == nil { 44 return data, nil 45 } 46 47 err := json.Unmarshal([]byte(*y), &data) 48 if err != nil { 49 return nil, apperrors.NewInvalidDataError("unable to unmarshal query parameters: %s", err.Error()) 50 } 51 52 return data, nil 53 } 54 55 // NewQueryParamsSerialized missing godoc 56 func NewQueryParamsSerialized(h map[string][]string) (QueryParamsSerialized, error) { 57 data, err := json.Marshal(h) 58 if err != nil { 59 return "", apperrors.NewInvalidDataError("unable to marshal query parameters: %s", err.Error()) 60 } 61 62 return QueryParamsSerialized(data), nil 63 }