From fb3a6fc969b0c8c286c7d024a108f5696627639c Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Tue, 18 Oct 2016 19:45:05 +0200 Subject: [PATCH] resolve scalar types in exec --- internal/exec/exec.go | 14 +++++++++++--- internal/schema/schema.go | 10 +--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/exec/exec.go b/internal/exec/exec.go index 2c699e1a42f..0936553d2d9 100644 --- a/internal/exec/exec.go +++ b/internal/exec/exec.go @@ -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 { @@ -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 { @@ -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 diff --git a/internal/schema/schema.go b/internal/schema/schema.go index 3e2de07aac6..b46ba60badd 100644 --- a/internal/schema/schema.go +++ b/internal/schema/schema.go @@ -18,8 +18,6 @@ type Type interface { isType() } -type Scalar struct{} - type Object struct { Name string Implements string @@ -44,7 +42,6 @@ type TypeReference struct { Name string } -func (Scalar) isType() {} func (Object) isType() {} func (Union) isType() {} func (Enum) isType() {} @@ -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(), } }