Reputation: 3
Error message when trying to make a post from graphQL, apparently it's a syntax error and I am not too familiar with SQL so I do not know what the error is. I am also using TypeORM so I don't know how a syntax error can occur here.
"query": "INSERT INTO \"post\"(\"title\", \"text\", \"points\", \"creatorId\", \"createdAt\", \"updatedAt\") VALUES ($1, $2, DEFAULT, DEFAULT, Sat Sep 05 2020 15:49:01 GMT+0200 (Central European Summer Time), Sat Sep 05 2020 15:49:01 GMT+0200 (Central European Summer Time)) RETURNING \"id\", \"points\", \"createdAt\", \"updatedAt\"",
and this is the error messge: "message": "syntax error at or near "Sep"",
The error occurs when using INSERT INTO and the error says it occurs at the word "Sep" so apparently something is wrong with the date or something although I don't understand how that makes sense.
This is the post resolver
@ObjectType()
@Entity()
export class Post extends BaseEntity {
@Field()
@PrimaryGeneratedColumn()
id!: number;
@Field()
@Column()
title!: string;
@Field()
@Column()
text!: string;
@Field()
@Column({ type: "int", default: 0})
points!: string;
@Field()
@Column()
creatorId: number;
@ManyToOne(() => User, (user) => user.posts)
creator: User;
@Field(() => String)
@CreateDateColumn()
createdAt = Date;
@Field(() => String)
@UpdateDateColumn()
updatedAt = Date;
}
This is the mutation
@Mutation(() => Post)
async createPost(@Arg("input") input: PostInput,
@Ctx() {req}: MyContext): Promise<Post> {
return Post.create({
...input,
creatorId: req.session!.userId,
}).save();
}
Upvotes: 0
Views: 1563
Reputation: 778
It seems you made a typo in your entity code :
@Field(() => String)
@CreateDateColumn()
createdAt : Date; //replace = with :
@Field(() => String)
@UpdateDateColumn()
updatedAt : Date; //replace = with :
Upvotes: 3