map.go

 1package graphql
 2
 3import (
 4	"encoding/json"
 5	"fmt"
 6	"io"
 7)
 8
 9func 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
18func 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}