Closed Giayychan closed 1 year ago
Noob here. I have the below schema declared however I can still save duplicate email data with mongoose and no errors are thrown. Am I doing something wrong?
userSchema.ts
import { composeMongoose } from 'graphql-compose-mongoose'; import { schemaComposer } from 'graphql-compose'; export interface IUser { firebaseUid: string; emailVerified: boolean; email: string; } export interface IUserDocument extends IUser, Document {} export const UserSchema = new Schema<IUser>({ emailVerified: { type: Boolean, required: true, default: false }, firebaseUid: { type: String, required: true, unique: true }, email: { type: String, required: true, unique: true } }); export const User = model<IUserDocument>('User', UserSchema); const customizationOptions = {}; export const UserTC = composeMongoose(User, customizationOptions); schemaComposer.Query.addFields({ userById: UserTC.mongooseResolvers.findById(), userMany: UserTC.mongooseResolvers.findMany() }); schemaComposer.Mutation.addFields({ userCreateOne: UserTC.mongooseResolvers.createOne(), userUpdateById: UserTC.mongooseResolvers.updateById(), userUpdateMany: UserTC.mongooseResolvers.updateMany(), userRemoveById: UserTC.mongooseResolvers.removeById() }); export const userSchema = schemaComposer.buildSchema(); export default userSchema;
package.json
"devDependencies": { "@types/express": "^4.17.14", "@types/jest": "^29.1.2", "@typescript-eslint/eslint-plugin": "^5.38.1", "@typescript-eslint/parser": "^5.38.1", "eslint": "^8.24.0", "jest": "^29.1.2", "nodemon": "^2.0.20", "ts-jest": "^29.0.3", "ts-node": "^10.9.1", "typescript": "^4.8.4" }, "dependencies": { "@apollo/server": "^4.0.0-rc.14", "body-parser": "^1.20.0", "cors": "^2.8.5", "dotenv": "^16.0.3", "express": "^4.18.1", "graphql": "^16.6.0", "graphql-compose": "^9.0.9", "graphql-compose-mongoose": "^9.7.2", "http": "^0.0.1-security", "mongoose": "^6.6.3" }
Noob here. I have the below schema declared however I can still save duplicate email data with mongoose and no errors are thrown. Am I doing something wrong?
userSchema.ts
package.json