Handling enums whose values contain a white space in GraphQL

Viewed 22

My project is in nestjs/graphql. I have a similar enum type to the following:

enum UserRoles {
    admin = 'admin',
    superAdmin = 'super admin'
}

registerEnumType(UserRoles, { name: 'UserRoles' })

In the database, user roles are stored as the values of this enum i.e. 'admin' and 'super admin'. However graphql takes enum elements from enum keys and has generated

enum UserRoles {
    admin
    superAdmin
}

However, then I'm getting conflicts between 'superAdmin' and 'super admin'.

I tried rewriting my enum as

enum UserRoles {
    admin = 'admin',
    'super admin' = 'super admin'
}

But then, as you can guess, graphql could not parse this and throwed an error while building.

How can I handle this kind of situations. What are the possible solutions except changing every document in the database from 'super admin' to 'superAdmin'.

0 Answers
Related