response.go

 1package graphql
 2
 3import (
 4	"context"
 5	"encoding/json"
 6	"fmt"
 7
 8	"github.com/vektah/gqlparser/gqlerror"
 9)
10
11// Errors are intentionally serialized first based on the advice in
12// https://github.com/facebook/graphql/commit/7b40390d48680b15cb93e02d46ac5eb249689876#diff-757cea6edf0288677a9eea4cfc801d87R107
13// and https://github.com/facebook/graphql/pull/384
14type Response struct {
15	Errors     gqlerror.List          `json:"errors,omitempty"`
16	Data       json.RawMessage        `json:"data"`
17	Extensions map[string]interface{} `json:"extensions,omitempty"`
18}
19
20func ErrorResponse(ctx context.Context, messagef string, args ...interface{}) *Response {
21	return &Response{
22		Errors: gqlerror.List{{Message: fmt.Sprintf(messagef, args...)}},
23	}
24}