package api import ( "fmt" "strings" ) // A QueryError is a GraphQL error. type QueryError struct { Message string `json:"message"` Path []string `json:"path"` } func (err QueryError) Error() string { return fmt.Sprintf("GraphQL: %s: %s", strings.Join(err.Path, "."), err.Message) } func (err QueryError) String() string { return err.Error() } // QueryErrorList is a list of query errors type QueryErrorList []QueryError func (errs QueryErrorList) Error() string { if len(errs) == 1 { return errs[0].Error() } return fmt.Sprintf("%s (+%d others)", errs[0].Error(), len(errs)-1) } func (errs QueryErrorList) String() string { return errs.Error() }