0

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();
  }

1 Answer 1

3

It seems you made a typo in your entity code :

@Field(() => String)
  @CreateDateColumn()
  createdAt : Date;  //replace = with :

  @Field(() => String)
  @UpdateDateColumn()
  updatedAt : Date;  //replace = with :
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.