【问题标题】:Sequelize, GraphJS : Cannot read property '2' of nullSequelize,GraphJS:无法读取 null 的属性“2”
【发布时间】: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: () =&gt; { 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


【解决方案1】:

您似乎不是唯一遇到问题的人:

https://github.com/sequelize/sequelize/issues/6725

https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/71

你也使用 mysql,如果是,是哪个版本?

似乎在某些版本中有效,而在某些版本中则无效:

https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/71#issuecomment-255192417

【讨论】:

    猜你喜欢
    • 2015-05-31
    • 1970-01-01
    • 2022-01-09
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    相关资源
    最近更新 更多