Skip to content

Commit

Permalink
introspection: type kind
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Oct 19, 2016
1 parent e2c58f2 commit 6f2399a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
16 changes: 13 additions & 3 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,25 @@ var tests = []struct {
resolver: &starwars.Resolver{},
query: `
{
__type(name: "Droid") {
a: __type(name: "Droid") {
name
kind
},
b: __type(name: "Character") {
name
kind
}
}
`,
result: `
{
"__type": {
"name": "Droid"
"a": {
"name": "Droid",
"kind": "OBJECT"
},
"b": {
"name": "Character",
"kind": "INTERFACE"
}
}
`,
Expand Down
21 changes: 20 additions & 1 deletion internal/exec/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,26 @@ type typeResolver struct {
}

func (r *typeResolver) Kind() string {
panic("TODO")
if r.scalar != "" {
return "SCALAR"
}
switch r.typ.(type) {
case *schema.Object:
return "OBJECT"
case *schema.Interface:
return "INTERFACE"
case *schema.Union:
return "UNION"
case *schema.Enum:
return "ENUM"
case *schema.Input:
return "INPUT_OBJECT"
case *schema.List:
return "LIST"
// TODO NON_NULL
default:
panic("unreachable")
}
}

func (r *typeResolver) Name() string {
Expand Down

0 comments on commit 6f2399a

Please sign in to comment.