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