I am using graphQL to retrieve data and mongoDb to create my user. When I run the signup mutation in apollo i get the error: Cannot return null for non-nullable field User.id.
I console.log(result) and it equals:
{ acknowledged: true, insertedId: new ObjectId("6432djjedh3i2o211i12je") }
This is not what I want returned as the result. I want result to equal the whole collection that was inserted, which is this:
{_id:6432djjedh3i2o211i12je email:"test@gmail.com" password: "$2a$10$ONkOjWbigkD3fWSo9XdweOzLePZM7CkGa0QgfbVLkyWtS10EU9R5uz8e" name:"name"} (from Mongo Atlas)
My whole signUp Mutation for creating a user is:
Mutation: {
signUp: async (_, {input }, { db}) => {
const hashedPassword = bcrypt.hashSync(input.password);
const newUser = {
...input,
password: hashedPassword
}
const result = await db.collection('Users').insertOne(newUser)
console.log(result);
//result gets reassigned as user
const user = result
return {
user,
token: 'token'
}
}
}
update tried console.log(result.ops[0]) instead but didnt work.