Here is my Apollo Client code:
mutation {
createUser(user_id: 3333, username: "third user", email: "[email protected]", password: "supersecret"){
user_id
username
email
password
}
}
And below is my typedef schema:
const typeDef = gql
`
type Query {
"These are the queries we define in our query type"
me(user_id: ID): User
}
"How to define the structure of user? Below is an object type that does this:"
type User {
user_id: ID,
username: String,
email: String,
password: String
}
type Mutation {
createUser(username: String!, email: String!, password: String, user_id: ID): User!
}
`;
Further, I am using sequalize ORM with postgres and my dbIndex is this:
const Sequelize = require('sequelize');
require('dotenv').config();
const sortDb = new Sequelize(
`${process.env.DATABASE}`,
process.env.DATABASE_USER,
process.env.DATABASE_PASSWORD,
{
dialect: 'postgres',
},
);
sortDb
.authenticate()
.then(() => {
console.log('Connected to SORT MY MIND DB');
})
.catch((err) => {
console.error('Unable to connect to DB', err);
});
// create a DB model which will correspond to
const account = sortDb.define('account', {
user_id: {type: Sequelize.INTEGER},
username: {type: Sequelize.STRING},
passowrd: {type: Sequelize.STRING},
email: {type: Sequelize.STRING}
});
module.exports.account = account;
My Query runs perfectly and fetches data from my postgres table. Why isnt mutation running? I see the following error : "Executing (default): INSERT INTO "accounts" ("id","user_id","username","email","createdAt","updatedAt") VALUES (DEFAULT,$1,$2,$3,$4,$5) RETURNING *; Unhandled rejection SequelizeDatabaseError: null value in column "password" violates not-null constraint".
This clearly means the Apollo client is trying to insult all null values into my table. How can I fix this?