Skip to content

Commit

Permalink
introspection: ofType
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Oct 21, 2016
1 parent 86da849 commit c4faac5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 8 additions & 1 deletion internal/exec/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ type InputObject struct {
}

type List struct {
Elem Type
OfType Type
}

type NonNull struct {
Elem Type
OfType Type
}

func (Scalar) isType() {}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c4faac5

Please sign in to comment.