In my graphQL API(with typescript & type-graphql) I'm trying to run a mutation which inputType has an enum value defined as below
export enum GenderType {
female = 'female',
male = 'male',
}
registerEnumType(GenderType, {
name: 'GenderType',
});
and I'm trying to execute this mutation.
mutation {
registerStudent(data: {
name: "John",
gender: "male",
}) {
id
}
}
but when I'm trying to execute the mutation it gives an error saying
"message": "Enum "GenderType" cannot represent non-enum value: "female". Did you mean the enum value "female" or "male"?",
I think this happens because how i defined the enum type using registerEnumType in type-graphql.
How to defile an enum with type-graphql
💡 Found the problem...
Actually problem located at mutation object data that I passed.
First I pass gender type as a String that cause the problem.
mutation {
registerStudent(data: {
name: "John",
gender: "male",
}) {
id
}
}
This is wrong bcz It's a String, Program is expecting a value we defined in enums so pass enum values as it is.
mutation {
registerStudent(data: {
name: "John",
gender: male,
}) {
id
}
}