Skip to content

Commit

Permalink
resolve scalar types in exec
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Oct 18, 2016
1 parent 4cb8dcc commit fb3a6fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 11 additions & 3 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ type Exec struct {
resolver reflect.Value
}

var builtinTypes = map[string]iExec{
"Int": &scalarExec{},
"Float": &scalarExec{},
"String": &scalarExec{},
"Boolean": &scalarExec{},
"ID": &scalarExec{},
}

func Make(s *schema.Schema, resolver interface{}) (*Exec, error) {
implementsMap := make(map[string][]string)
for _, t := range s.Types {
Expand Down Expand Up @@ -55,9 +63,6 @@ func (e *Exec) Exec(document *query.Document, variables map[string]interface{},

func makeExec(s *schema.Schema, t schema.Type, resolverType reflect.Type, implementsMap map[string][]string, typeRefMap map[typeRefMapKey]*typeRefExec) (iExec, error) {
switch t := t.(type) {
case *schema.Scalar:
return &scalarExec{}, nil

case *schema.Object:
fields := make(map[string]*fieldExec)
for name, f := range t.Fields {
Expand Down Expand Up @@ -113,6 +118,9 @@ func makeExec(s *schema.Schema, t schema.Type, resolverType reflect.Type, implem
}, nil

case *schema.TypeReference:
if builtin, ok := builtinTypes[t.Name]; ok {
return builtin, nil
}
e, err := resolveType(s, t.Name, resolverType, implementsMap, typeRefMap)
return e, err

Expand Down
10 changes: 1 addition & 9 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ type Type interface {
isType()
}

type Scalar struct{}

type Object struct {
Name string
Implements string
Expand All @@ -44,7 +42,6 @@ type TypeReference struct {
Name string
}

func (Scalar) isType() {}
func (Object) isType() {}
func (Union) isType() {}
func (Enum) isType() {}
Expand Down Expand Up @@ -215,13 +212,8 @@ func parseType(l *lexer.Lexer) Type {
return parseList(l)
}

name := l.ConsumeIdent()
switch name {
case "Int", "Float", "String", "Boolean", "ID":
return &Scalar{}
}
return &TypeReference{
Name: name,
Name: l.ConsumeIdent(),
}
}

Expand Down

0 comments on commit fb3a6fc

Please sign in to comment.