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 {