gpt4 book ai didi

node.js - 为什么即使已指定值,Apollo 客户端仍将空值插入到所有字段的表中?

转载 作者:行者123 更新时间:2023-12-03 22:37:56 26 4
gpt4 key购买 nike

这是我的 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 表中获取数据。为什么突变不运行?我看到以下错误:“Executing (default): INSERT INTO "accounts"("id","user_id","username","email","createdAt","updatedAt") VALUES (DEFAULT,$1,$2, $3,$4,$5) 返回 *;
未处理的拒绝 SequelizeDatabaseError:“密码”列中的空值违反了非空约束”。

这显然意味着 Apollo 客户端正试图将所有空值放入我的表中。我怎样才能解决这个问题?

最佳答案

啊,这是 dbIndex 中的一个错字!!! “密码”呼:D

关于node.js - 为什么即使已指定值,Apollo 客户端仍将空值插入到所有字段的表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55660583/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com