Search code examples
graphqlaws-appsync

How to use special character (-) in appsync enum?


I would like to represent locale information using appsync Type enum. However, there are some special inside locale information. e.g. the - in en-US, en-UK.

If it is possible, I want to retain the format of the locale string.


Solution

  • The GraphQL specification does not allow - in names. So the answer is simply that it is not possible.

    What you could do is create an object type that wraps the enum and the locale string:

    enum LocaleIdentifier {
      EN_US
      EN_UK
      # ...
    }
    
    type Locale {
      id: LocaleIdentifier
      str: String
    }
    

    This would allow you to use the string in the frontend every time you get a Locale but reference the locale with an enum type. I am not sure if there is a lot of value in that instead of simply using the string directly.