I am trying to create a GQL mutation by TypeORM and using SQL Server as database. If I am trying to run the mutation it is throwing exception. Sharing the code below;
index.ts
(async () => {
const app = express();
await createConnection();
const apolloServer = new ApolloServer({
schema: await buildSchema({
resolvers: [UserRegistrationResolver, HealthResolver],
}),
tracing: true,
context: ({ req, res }) => ({ req, res })
});
apolloServer.applyMiddleware({ app, cors: false });
app.listen(4000, () => {
console.log("App is started");
})
})();
GQL Types:
@InputType()
export class UserRegistrationType {
/*......*/
@Field()
Reg_Security_Qus_Ans: string;
/*......*/
}
Entity:
@ObjectType()
@Entity()
export class User_Registration extends BaseEntity {
/*......*/
@Field(() => Int)
@OneToOne(()=> Security_Questions)
@JoinColumn()
Reg_Security_Qus_ID: Security_Questions;
/*......*/
}
Mutation:
@Resolver()
export class UserRegistrationResolver {
@Mutation(() => User_Registration)
async createRegistrations(
@Arg("RegistrationMutation") registrationMutation: UserRegistrationType
) {
console.log("Boom1");
let oneUser = await User_Registration.insert(registrationMutation);
return oneUser;
}
@Query(() => User_Registration)
getUsers() {
console.log("Boom");
return User_Registration.find();
}
}
When, I am trying to execute the mutation some weird error is appearing like below, asking me for 'class-validator', the error looks something like this,
"message": "Cannot find module 'class-validator'\nRequire stack:\n-
Can anyone help me to solve this. I am stuck with this. Thanks in advance.
I was stupid, I had to install
npm i class-validator
this package. thats all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With