I have encountered an issue in my project where I keep getting a red underline at a specific line of code:
{
username: options.username,
password: hasedPassword
}
Upon hovering over it, the error message reads as follows:
Argument of type '{ username: string; password: string; }' is not assignable to parameter of type 'RequiredEntityData'. Type '{ username: string; password: string; }' is missing the following properties from type '{ createdAt: EntityDataItem; updatedAt: EntityDataItem; username: EntityDataItem; password: EntityDataItem; }': createdAt, updatedAtts(2345)
For reference, here is the complete file structure:
import { User } from "../entities/User";
import { MyContext } from "../types";
import { Arg, Ctx, Field, InputType, Mutation, Resolver } from "type-graphql";
import argon2 from 'argon2';
@InputType()
class UsernamePasswordInput {
@Field()
username: string
@Field()
password: string
}
@Resolver()
export class UserResolver {
@Mutation(() => User)
async register(
@Arg('options') options: UsernamePasswordInput,
@Ctx() {em}: MyContext
) {
const hasedPassword = await argon2.hash(options.password)
const user = em.create(User, {
username: options.username,
password: hasedPassword
})
await em.persistAndFlush(user)
return user
}
}
Additionally, here's the content of package.json:
{
"name": "practicegraphQL",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"watch": "tsc -w",
"dev": "nodemon dist/index.js",
"start": "ts-node src/index.ts",
"create:migration": "mikro-orm migration:create"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^17.0.35",
"nodemon": "^2.0.16",
"ts-node": "^10.8.0",
"typescript": "^4.6.4"
},
"dependencies": {
"@mikro-orm/cli": "^5.1.4",
"@mikro-orm/core": "^5.1.4",
"@mikro-orm/migrations": "^5.1.4",
"@mikro-orm/postgresql": "^5.1.4",
"apollo-server-express": "^2.25.3",
"argon2": "^0.28.5",
"express": "^4.18.1",
"graphql": "15.7.2",
"pg": "^8.7.3",
"reflect-metadata": "^0.1.13",
"type-graphql": "^1.1.1"
},
"mikro-orm": {
"useTsNode": true,
"configPaths": [
"./src/mikro-orm.config.ts",
"./dist/mikro-orm.config.js"
]
}
}
If you have any insights on how to resolve this error, your input would be greatly appreciated. Thank you!
As an update, I have included the User entity for reference:
@ObjectType()
@Entity()
export class User {
@Field()
@PrimaryKey()
_id!: number;
@Field(() => String)
@Property()
createdAt: Date = new Date();
@Field(() => String)
@Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();
@Field(() => String)
@Property({unique: true})
username!: string;
@Property()
password!: string;
}