这是我的Apollo客户代码:
mutation {
createUser(user_id: 3333, username: "third user", email: "third@email.com", password: "supersecret"){
user_id
username
email
password
}
}
下面是我的typedef模式:
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!
}
`;
此外,我在postgres中使用sequalize ORM,而我的dbIndex是这样的:
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;
我的查询运行完美,并从postgres表中获取数据。为什么不运行突变?我看到以下错误:“正在执行(默认):INSERT INTO“ accounts”(“ id”,“ user_id”,“ username”,“ email”,“ createdAt”,“ updatedAt”)VALUES(DEFAULT,$ 1,$ 2, $ 3,$ 4,$ 5)返回*; 未处理的拒绝SequelizeDatabaseError:“密码”列中的空值违反了非空约束”。
这显然意味着Apollo客户端正在尝试将所有空值侮辱到我的表中。我该如何解决?
答案 0 :(得分:0)
嗯,这是dbIndex中的错字!!! “密码” Phew:D