diff --git a/errors/errors.go b/errors/errors.go index af4d6e81c18..ad435d15923 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -3,10 +3,10 @@ package errors import "fmt" type QueryError struct { - Message string `json:"message"` - Locations []*Location `json:"locations,omitempty"` - Rule string `json:"-"` - ResolverError error `json:"-"` + Message string `json:"message"` + Locations []Location `json:"locations,omitempty"` + Rule string `json:"-"` + ResolverError error `json:"-"` } type Location struct { diff --git a/internal/common/values.go b/internal/common/values.go index 705f0fd6f74..2589664cd6b 100644 --- a/internal/common/values.go +++ b/internal/common/values.go @@ -28,7 +28,7 @@ func (l InputValueList) Get(name string) *InputValue { type ValueWithLoc struct { Value interface{} - Loc *errors.Location + Loc errors.Location } func ParseInputValue(l *lexer.Lexer) *InputValue { diff --git a/internal/lexer/lexer.go b/internal/lexer/lexer.go index 823689a3491..654be41a87c 100644 --- a/internal/lexer/lexer.go +++ b/internal/lexer/lexer.go @@ -22,7 +22,7 @@ type Literal struct { type Ident struct { Name string - Loc *errors.Location + Loc errors.Location } type Variable string @@ -38,7 +38,7 @@ func (l *Lexer) CatchSyntaxError(f func()) (errRes *errors.QueryError) { if err := recover(); err != nil { if err, ok := err.(syntaxError); ok { errRes = errors.Errorf("syntax error: %s", err) - errRes.Locations = []*errors.Location{l.Location()} + errRes.Locations = []errors.Location{l.Location()} return } panic(err) @@ -129,8 +129,8 @@ func (l *Lexer) SyntaxError(message string) { panic(syntaxError(message)) } -func (l *Lexer) Location() *errors.Location { - return &errors.Location{ +func (l *Lexer) Location() errors.Location { + return errors.Location{ Line: l.sc.Line, Column: l.sc.Column, } diff --git a/internal/query/query.go b/internal/query/query.go index 47bdb436203..7832474cb19 100644 --- a/internal/query/query.go +++ b/internal/query/query.go @@ -54,7 +54,7 @@ type Field struct { Arguments common.ArgumentList Directives map[string]common.ArgumentList SelSet *SelectionSet - Location *errors.Location + Loc errors.Location } type FragmentSpread struct { @@ -212,7 +212,7 @@ func parseSelection(l *lexer.Lexer) Selection { func parseField(l *lexer.Lexer) *Field { f := &Field{ - Location: l.Location(), + Loc: l.Location(), } f.Alias = l.ConsumeIdent() f.Name = f.Alias diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 4ac3b1d5a8b..6b21cd1df11 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -15,10 +15,10 @@ import ( "github.com/neelance/graphql-go/internal/schema" ) -func addErr(errs *[]*errors.QueryError, loc *errors.Location, rule string, format string, a ...interface{}) { +func addErr(errs *[]*errors.QueryError, loc errors.Location, rule string, format string, a ...interface{}) { *errs = append(*errs, &errors.QueryError{ Message: fmt.Sprintf(format, a...), - Locations: []*errors.Location{loc}, + Locations: []errors.Location{loc}, Rule: rule, }) } @@ -89,7 +89,7 @@ func validateSelection(s *schema.Schema, sel query.Selection, t common.Type) (er f := fields(t).Get(sel.Name) if f == nil && t != nil { suggestion := makeSuggestion("Did you mean", fields(t).Names(), sel.Name) - addErr(&errs, sel.Location, "FieldsOnCorrectType", "Cannot query field %q on type %q.%s", sel.Name, t, suggestion) + addErr(&errs, sel.Loc, "FieldsOnCorrectType", "Cannot query field %q on type %q.%s", sel.Name, t, suggestion) } if f != nil {