1

I created a field in a model named "Listing". The field in here is "category". This is set to enum of some values (screenshot below). Does graphql allow to query to fetch the enum list?

Noitidart
  • 35,443
  • 37
  • 154
  • 323

2 Answers2

5

This is possible using a GraphQL introspection query.

Enum types on Graphcool are named "MODEL_FIELD", so in your case you can run this query:

{
  __type(name: "LISTING_CATEGORY") {
    name
    enumValues {
      name
    }
  }
}

You can find more information in this answer to a similar question.

Community
  • 1
  • 1
marktani
  • 7,578
  • 6
  • 37
  • 60
  • 1
    Thanks! I'm new to GraphQL so your relating it back to "GraphQL introspection query" helps me a lot. As when I'm new to stuff, the first challenge for me is to get used to its docs. – Noitidart Feb 13 '17 at 19:22
  • 2
    You can find more information on introspection queries here: http://graphql.org/learn/introspection/ – marktani Feb 14 '17 at 09:59
1

An easier approach, when using Nexus.js, is to just create a new root type, and have it resolve to your array of ENUM values. This works because with Nexus.js you're writing your schema with code (TypeScript), which means you're able to import your array of ENUM values into the resolver — it's just code.

Gunar Gessner
  • 2,331
  • 23
  • 23