From c4faac56a02f7743de55bc20b261fb749578afa8 Mon Sep 17 00:00:00 2001
From: Richard Musiol <mail@richard-musiol.de>
Date: Fri, 21 Oct 2016 15:37:12 +0200
Subject: [PATCH] introspection: ofType

---
 internal/exec/exec.go          | 4 ++--
 internal/exec/introspection.go | 9 ++++++++-
 internal/schema/schema.go      | 8 ++++----
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/internal/exec/exec.go b/internal/exec/exec.go
index 22a8d0a6f9..47e7bac7f5 100644
--- a/internal/exec/exec.go
+++ b/internal/exec/exec.go
@@ -132,13 +132,13 @@ func makeExec2(s *schema.Schema, t schema.Type, nonNull bool, resolverType refle
 			return nil, fmt.Errorf("%s is not a slice", resolverType)
 		}
 		e := &listExec{nonNull: nonNull}
-		if err := makeExec(&e.elem, s, t.Elem, resolverType.Elem(), typeRefMap); err != nil {
+		if err := makeExec(&e.elem, s, t.OfType, resolverType.Elem(), typeRefMap); err != nil {
 			return nil, err
 		}
 		return e, nil
 
 	case *schema.NonNull:
-		return makeExec2(s, t.Elem, true, resolverType, typeRefMap)
+		return makeExec2(s, t.OfType, true, resolverType, typeRefMap)
 
 	default:
 		panic("invalid type")
diff --git a/internal/exec/introspection.go b/internal/exec/introspection.go
index b543d3db72..af8d7e4f7a 100644
--- a/internal/exec/introspection.go
+++ b/internal/exec/introspection.go
@@ -291,7 +291,14 @@ func (r *typeResolver) InputFields() *[]*inputValueResolver {
 }
 
 func (r *typeResolver) OfType() *typeResolver {
-	panic("TODO")
+	switch t := r.typ.(type) {
+	case *schema.List:
+		return &typeResolver{t.OfType}
+	case *schema.NonNull:
+		return &typeResolver{t.OfType}
+	default:
+		return nil
+	}
 }
 
 type fieldResolver struct {
diff --git a/internal/schema/schema.go b/internal/schema/schema.go
index e35db18271..9b3994736b 100644
--- a/internal/schema/schema.go
+++ b/internal/schema/schema.go
@@ -60,11 +60,11 @@ type InputObject struct {
 }
 
 type List struct {
-	Elem Type
+	OfType Type
 }
 
 type NonNull struct {
-	Elem Type
+	OfType Type
 }
 
 func (Scalar) isType()      {}
@@ -310,14 +310,14 @@ func parseType(target *Type, l *lexer.Lexer, c *context) {
 			l.ConsumeToken('!')
 			nn := &NonNull{}
 			*target = nn
-			target = &nn.Elem
+			target = &nn.OfType
 		}
 	}
 
 	if l.Peek() == '[' {
 		l.ConsumeToken('[')
 		t := &List{}
-		parseType(&t.Elem, l, c)
+		parseType(&t.OfType, l, c)
 		l.ConsumeToken(']')
 		parseNonNil()
 		*target = t