Skip to content

Commit

Permalink
parse type in query
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Oct 23, 2016
1 parent be87a8f commit bec4536
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions internal/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/neelance/graphql-go/errors"
"github.com/neelance/graphql-go/internal/lexer"
"github.com/neelance/graphql-go/internal/schema"
)

type Document struct {
Expand All @@ -30,7 +31,7 @@ const (

type VariableDef struct {
Name string
Type string
Type schema.Type
}

type NamedFragment struct {
Expand Down Expand Up @@ -169,10 +170,7 @@ func parseVariableDef(l *lexer.Lexer) *VariableDef {
l.ConsumeToken('$')
v.Name = l.ConsumeIdent()
l.ConsumeToken(':')
v.Type = l.ConsumeIdent()
if l.Peek() == '!' {
l.ConsumeToken('!') // TODO
}
v.Type = schema.ParseType(l)
return v
}

Expand Down
8 changes: 4 additions & 4 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func parseFields(l *lexer.Lexer) (map[string]*Field, []string) {
l.ConsumeToken(')')
}
l.ConsumeToken(':')
f.Type = parseType(l)
f.Type = ParseType(l)
fields[f.Name] = f
fieldOrder = append(fieldOrder, f.Name)
}
Expand All @@ -360,15 +360,15 @@ func parseInputValue(l *lexer.Lexer) *InputValue {
p := &InputValue{}
p.Name = l.ConsumeIdent()
l.ConsumeToken(':')
p.Type = parseType(l)
p.Type = ParseType(l)
if l.Peek() == '=' {
l.ConsumeToken('=')
p.Default = parseValue(l)
}
return p
}

func parseType(l *lexer.Lexer) Type {
func ParseType(l *lexer.Lexer) Type {
t := parseNullType(l)
if l.Peek() == '!' {
l.ConsumeToken('!')
Expand All @@ -380,7 +380,7 @@ func parseType(l *lexer.Lexer) Type {
func parseNullType(l *lexer.Lexer) Type {
if l.Peek() == '[' {
l.ConsumeToken('[')
ofType := parseType(l)
ofType := ParseType(l)
l.ConsumeToken(']')
return &List{OfType: ofType}
}
Expand Down

0 comments on commit bec4536

Please sign in to comment.