【发布时间】:2023-03-21 02:29:01
【问题描述】:
当我在模型中定义一个唯一列时,我正在使用 GraphJS 和 sequelize:
const Product = Connection.define('Product', {
label: {
type: Sequelize.STRING,
allowNull: false,
unique: true <--------------
},
description: {
type: Sequelize.TEXT,
allowNull: false
},
price: {
type: Sequelize.FLOAT(6, 3),
}
});
当我尝试插入具有相同标签的第二行时:
const Mutations = new GraphQLObjectType({
name: 'Mutations',
description: 'All Mutations',
fields: () => {
return {
addProduct: {
type: Product,
args: {
new: {
name: 'New product',
type: ProductInput
}
},
resolve(_, args) {
return Db.models.Product.create(args.new);
}
},
};
}
});
我收到以下错误:
TypeError: Cannot read property '2' of null
有什么想法吗?
【问题讨论】:
-
可能显示插入代码?
-
const Mutations = new GraphQLObjectType({ name: 'Mutations', description: 'All Mutations', fields: () => { return { addProduct: { type: Product, args: { new: { name: 'New product', type: ProductInput } }, resolve(_, args) { return Db.models.Product.create(args.new); } }, }; } });
标签: node.js sequelize.js graphql-js