Search code examples
postgresqltypeormtypegraphql

error: error: syntax error at or near "Oct" Postgres db


I am getting this error "error: error: syntax error at or near "Oct" whenever I want to create a new post in my postgres db using apollo graphql and typeorm. I have checked the code over and over again but can't seem to find the problem. This is my code:

This is the post resolver from post.ts: `

@Mutation(() => Post)
    createPost(@Arg('title') title: string): Promise<Post> {
        //2 sql queries
        return Post.create({ title }).save()
    }

`


Solution

  • Fixed the issue. The error had to do with the data type of the date. The data type I passed initially to the date object using typeorm was just Date so it was reading the type as an Oct and not a string. So I changed the date type to new Date() and it solved the issue.

    Instead of:

    createdAt: Date

    It should be:

    createdAt: new Date()