Skip to content

Commit

Permalink
introspection: enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Oct 21, 2016
1 parent cb423e6 commit 7da95f4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
32 changes: 32 additions & 0 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions internal/exec/introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7da95f4

Please sign in to comment.