Absinthe enum field... can it expose lowercase values?

In my Absinthe input types, I want to use an enum field to restrict input to a list of known values – importantly, this is done to make life easier for the front-end scripts which will be sending values into our GraphQL API.

I’ve noticed that the enum macro always upcases all the values, so even though I want the incoming values to be restricted to fooBar and myThing (i.e. camelCase), Absinthe seems to always convert this to FOOBAR and CAMELCASE.

I’m looking at the source code in Absinthe.Schema.Notation and I can see the handle_enum_value_attrs function includes a call to String.upcase that I think is the culprit, but I don’t yet follow the flow well enough to see if there’s a workaround for having the values restricted to the camelCases for the front end. (I did see the as: option, but that only affects the value on the back-end).

Thanks for any pointers.

You have to directly set the :name. Here’s an example:

  enum :status_enum do
    value :active, name: "active"
    value :inactive, name: "inactive"
  end
6 Likes

It’s worth noting that it appears that the GraphQL “best practice” is SHOUTING_ENUMS rather than something case sensitive.

4 Likes

Good to know. In our case, we’re throwing a bone to a set of specific client scripts for a private API, so…