MCPcopy
hub / github.com/dgraph-io/dgraph / WriteTo

Method WriteTo

graphql/schema/response.go:129–141  ·  view source on GitHub ↗

WriteTo writes the GraphQL response as unindented JSON to w and returns the number of bytes written and error, if any.

(w io.Writer)

Source from the content-addressed store, hash-verified

127// WriteTo writes the GraphQL response as unindented JSON to w
128// and returns the number of bytes written and error, if any.
129func (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
144func (r *Response) Output() interface{} {

Callers 5

TestDataAndErrorsFunction · 0.95
TestWriteTo_BadDataFunction · 0.95
TestNilResponseFunction · 0.95
TestErrorResponseFunction · 0.80
writeFunction · 0.80

Calls 3

OutputMethod · 0.95
WriteMethod · 0.65
ErrorfMethod · 0.45

Tested by 4

TestDataAndErrorsFunction · 0.76
TestWriteTo_BadDataFunction · 0.76
TestNilResponseFunction · 0.76
TestErrorResponseFunction · 0.64