From 6f2399aa0eec93f27bb784a7436e4da08cd92f30 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Wed, 19 Oct 2016 14:28:30 +0200 Subject: [PATCH] introspection: type kind --- graphql_test.go | 16 +++++++++++++--- internal/exec/introspection.go | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/graphql_test.go b/graphql_test.go index f7049d9d700..162dd47981c 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -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" } } `, diff --git a/internal/exec/introspection.go b/internal/exec/introspection.go index 8b02a8f8d62..dd1e86f4b11 100644 --- a/internal/exec/introspection.go +++ b/internal/exec/introspection.go @@ -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 {