graphqlapollo-servervue-apollo

Is there an option to query enum description instead of value


I query some type from graphql schema, and for a specific field, I want to get it with the enum description instead of the enum value.

type Gigi {
   a: SomeEnum!
   b: Int!
}

enum SomeEnum {
   "Bla"
   BLA

   "Foo"
   FOO
}

I want to get the 'Gigi.a' field, with the description of the enum. For example:

{
   a: "Bla"
   b: 5
}

Does anyone know if this is possible?


Solution

  • Descriptions of types, fields and enum values exist for documentation purposes only and are therefore only accessibly through an introspection query:

    query {
      __type(name: "SomeEnum") {
        enumValues {
          name
          description
        }
      }
    }
    

    Also note that there is nothing in the spec that requires enum values to be in all caps, so you can have an enum like:

    enum SomeEnum {
      Bla
      Foo
    }