Skip to content

Commit

Permalink
refactor: Location without pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Mar 22, 2017
1 parent 5a40251 commit 885af60
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/common/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Literal struct {

type Ident struct {
Name string
Loc *errors.Location
Loc errors.Location
}

type Variable string
Expand All @@ -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)
Expand Down Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions internal/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 885af60

Please sign in to comment.