In the previous post, we have seen how to save User Passwords.
Let’s check use of enumerations or enums.
Hypi facilitates declaring a list of items in enumerations format. You may declare your own enum in the schema.
enum Color {
YELLOW
BLUE
GREEN
}
There are in-built enums that you can use in your application. Check Core app.
Enums can only have a finite set of values. Values apart from the listed ones are not allowed.
Use enum as a field type in any data type.
type ChooseColor {
current: Color
}
Insert or update enum value using upsert.
mutation {
upsert(values: { ChooseColor: [{ current: GREEN }] }) {
id
}
}
#result
{
"data": {
"upsert": [
{
"id": "01gespecz4azc8nwn5vs5fs9ct"
}
]
}
}
Retrieve enum value using get function.
{
get(type: ChooseColor, id: "01gespecz4azc8nwn5vs5fs9ct") {
... on ChooseColor {
current
}
}
}
#result
{
"data": {
"get": {
"current": "GREEN"
}
}
}