github.com/zikaeroh/gqlgen@v0.7.2/graphql/map.go (about) 1 package graphql 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io" 7 ) 8 9 func MarshalMap(val map[string]interface{}) Marshaler { 10 return WriterFunc(func(w io.Writer) { 11 err := json.NewEncoder(w).Encode(val) 12 if err != nil { 13 panic(err) 14 } 15 }) 16 } 17 18 func UnmarshalMap(v interface{}) (map[string]interface{}, error) { 19 if m, ok := v.(map[string]interface{}); ok { 20 return m, nil 21 } 22 23 return nil, fmt.Errorf("%T is not a map", v) 24 }