'Accept only specified values' validations should use GraphQL enum

The GraphQL specification supports enums.

It would help with type validation if validation of fields where specified values should be used use GraphQL enums.

It would be especially useful with GraphQL codegen utilities.

GraphCMS supports this by letting you define enum types that can then be used as the field type in multiple models’ fields.

Totally agree.

We use typescript and graphql.
We generate all the types of our application with graphql-code-generator
In Dato we have several text fields in many models which accept only a list of values.
Unfortunately those fields are just Scalar['String'] instead of an enum.

For example, we would like to have a User model with gender field. this field value could be only “man” or “woman”. But it would become a simple string which could take any value.

1 Like