Alisson Alisson - 1 year ago 123
React JSX Question

How to list members from an GraphQL's Enum type with ReactJS

I have a GraphQL mutation that accepts an Enum as one of the inputs, I would like to list those enum's members as a select on the UI. How should I do that? Do I need to hard code the members to the select?

Answer Source

You can use the __type field to get an enum type's values. For example, you could ask for the values of a Color enum:

   __type(name: "Color") {
     enumValues {

And it might return a response like:

  "data" : {
    "__type" : {
      "enumValues" : [
        { "name" : "WHITE" },
        { "name" : "BLUE" },
        { "name" : "BLACK" },
        { "name" : "RED" },
        { "name" : "GREEN" },

Then, you could use that response to render the UI.

More info about GraphQL Introspection:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download