WriteTo writes the GraphQL response as unindented JSON to w and returns the number of bytes written and error, if any.
(w io.Writer)
| 127 | // WriteTo writes the GraphQL response as unindented JSON to w |
| 128 | // and returns the number of bytes written and error, if any. |
| 129 | func (r *Response) WriteTo(w io.Writer) (int64, error) { |
| 130 | js, err := json.Marshal(r.Output()) |
| 131 | |
| 132 | if err != nil { |
| 133 | msg := "Internal error - failed to marshal a valid JSON response" |
| 134 | glog.Errorf("%+v", errors.Wrap(err, msg)) |
| 135 | js = []byte(fmt.Sprintf( |
| 136 | `{ "errors": [{"message": "%s"}], "data": null }`, msg)) |
| 137 | } |
| 138 | |
| 139 | i, err := w.Write(js) |
| 140 | return int64(i), err |
| 141 | } |
| 142 | |
| 143 | // Output returns json interface of the response |
| 144 | func (r *Response) Output() interface{} { |