Sequelizedatabaseerror - Syntax error when creating an ARRAY field in Graphql with sequelize and mysql

Asked

Viewed 64 times

1

I am developing a basic API for blog graphql with Sequelize and Mysql as a database, everything works perfectly until I try to create a new keyword field of the Array type, for blog posts, I believe it is some simple detail, but as I have no experience, I could not solve it yet.

Error:

Unhandled rejection SequelizeDatabaseError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[] NOT NULL DEFAULT , `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NU' at line 1

Postmodel:

sequelize.define('Post', {
    id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true,
        autoIncrement: true
    },
    title: {
        type: DataTypes.STRING,
        allowNull: false
    },
    content: {
        type: DataTypes.TEXT,
        allowNull: false
    },
    photo: {
        type: DataTypes.BLOB({
            length: 'long'
        }),
        allowNull: false
    },
    category: {
        type: DataTypes.STRING,
        allowNull: false
    },
    slug: {
        type: DataTypes.STRING,
        allowNull: false
    },
    highlight: {
        type: DataTypes.BOOLEAN,
        allowNull: false
    },
    keyword: {
        type: DataTypes.ARRAY(DataTypes.STRING),
        allowNull: false,
        defaultValue: []
    }
}, {
    tableName: 'posts'
});

Post Schema:

const postTypes = `

    type Post {
        id: ID!
        title: String!
        content: String!
        photo: String!
        createdAt: String!
        updated: String!
        author: User!
        comments(first: Int, offset: Int): [ Comment! ]!
        category: String!
        slug: String!
        highlight: Boolean!
        keyword: [String!] !
    }

    input PostInput {
        title: String!
        content: String!
        photo: String!
        category: String!
        slug: String!
        highlight: Boolean!
        keyword: [String!] !
    }

`;
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.