From 7da95f4a932a8ce4dae85f7b8924294d041f55d9 Mon Sep 17 00:00:00 2001 From: Richard Musiol Date: Fri, 21 Oct 2016 13:09:22 +0200 Subject: [PATCH] introspection: enum values --- graphql_test.go | 32 ++++++++++++++++++++++++++++++++ internal/exec/introspection.go | 14 ++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/graphql_test.go b/graphql_test.go index aa67e62168f..9ed945242fd 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -745,6 +745,38 @@ var tests = []struct { } `, }, + + { + name: "StarWarsIntrospection5", + schema: starwars.Schema, + resolver: &starwars.Resolver{}, + query: ` + { + __type(name: "Episode") { + enumValues { + name + } + } + } + `, + result: ` + { + "__type": { + "enumValues": [ + { + "name": "NEWHOPE" + }, + { + "name": "EMPIRE" + }, + { + "name": "JEDI" + } + ] + } + } + `, + }, } func TestAll(t *testing.T) { diff --git a/internal/exec/introspection.go b/internal/exec/introspection.go index 12c88e5fb6f..07a2282df53 100644 --- a/internal/exec/introspection.go +++ b/internal/exec/introspection.go @@ -251,7 +251,16 @@ func (r *typeResolver) PossibleTypes() []*typeResolver { } func (r *typeResolver) EnumValues(args struct{ IncludeDeprecated bool }) []*enumValueResolver { - panic("TODO") + t, ok := r.typ.(*schema.Enum) + if !ok { + return nil + } + + l := make([]*enumValueResolver, len(t.Values)) + for i, v := range t.Values { + l[i] = &enumValueResolver{v} + } + return l } func (r *typeResolver) InputFields() []*inputValueResolver { @@ -319,10 +328,11 @@ func (r *inputValueResolver) DefaultValue() *string { } type enumValueResolver struct { + value string } func (r *enumValueResolver) Name() string { - panic("TODO") + return r.value } func (r *enumValueResolver) Description() string {