Hussam Khatib
06/27/2022, 2:45 PMenum Gender{
M
F
Other
}
I want this in the client as
const genders = ["M","F","Other"]
without hardcoding.Ian Ray
06/27/2022, 4:05 PMHussam Khatib
06/27/2022, 4:24 PMmodel student {
gender : Gender!
}
enum Gender { M F Other}
In the frontend I want to use it the gender them , Basically update profile I will be providing a dropdown to select the gender. That's why I need to store them in an array client side.
I am looking If there is a way to do it rather hard coding it.Roryl
06/27/2022, 5:57 PMGender enum you can grab it (in object form) with import { Gender } from "@prisma/client" and if you really need it in an array form you can use any method like Object.values to get an array of the values.Ian Ray
06/27/2022, 6:05 PMIan Ray
06/27/2022, 6:05 PMRoryl
06/27/2022, 6:12 PMIan Ray
06/27/2022, 6:22 PMIan Ray
06/27/2022, 6:29 PMHussam Khatib
06/28/2022, 3:43 AMBjörnstjerne Tiedemann
06/28/2022, 6:43 AMimport { enumType, extendType } from 'nexus';
import { Gender } from '@necom/lib/prismaAdmin';
export const GenderEnum = enumType({
name: 'Gender',
members: Gender,
});
export const getGenderEnum = extendType({
type: 'AllEnum',
definition: (t) => {
t.list.field('Gender', {
type: 'Gender',
resolve: () => {
return Object.values(Gender);
},
});
},
});
AllEnum Type is used by a Query as result. The client can request all enums needed with the Prisma definition. So database -> backend -> client use the same values.