'Update not working on newly added column in GraphQL
I created new column in MySQL db i.e. otp and trying to update this by using below Mutation but it's not working, however same function updating all other columns like name of user but not updating otp column. I added otp column in user's Schema & model as well. Can anyone help me in finding what exactly I am missing in this. One more point when retrieving data from user's table otp field always null.
sendotp: async (_, {email }) => {
return User.findOne({
where: {
email: email,
},
limit: 1,
}).then(async (user) => {
if (user) {
otp = Math.floor(Math.random() * 1000);
let updatedUser = await User.update(
{ otp: otp, name:otp },
{ where: { id: user.id }, returning: true }
);
return user;
}
else
{
throw new AuthenticationError("An account does not exist with this email.");
}
});
}
Here is schema extend type Mutation { sendotp(email: String!): User }
type User {
id: ID!
uuid: String
name: String
email: String
otp: String
}
Model of above resolver as
"use strict";
module.exports = (sequelize, DataTypes) => {
var User = sequelize.define(
"User",
{
uuid: DataTypes.STRING,
name: DataTypes.STRING,
email: DataTypes.STRING,
otp: DataTypes.STRING,
} ....
Resolver not returning otp filed in simple select query as well. Select query result as
{\"id\":435,\"uuid\":\"dfds\",\"name\":\"602a\",\"email\":\"[email protected]\",}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|