0

I am using the mongdb database with graphql. But, graphql mutation createUser is returning null

{
 "data": {
    "createUser": null
  }
}

here is my mutation resolver code:

createUser: async args => {
        try {
          const existingUser = await User.findOne({ email: args.userInput.email });
          if (existingUser) {
            throw new Error('User exists already.');
          }
          const hashedPassword = await bcrypt.hash(args.userInput.password, 12);

          const user = new User({
            email: args.userInput.email,
            password: hashedPassword,
            username:args.userInput.username
          });

          const result = await user.save();

          return { ...result._doc, password: null, _id: result.id ,username:result.username};
        } catch (err) {
          throw err;
        }
    }
};

Please help. Everything seems right to me. Thanks in advance.

Afrida Anzum
  • 563
  • 4
  • 19
  • https://stackoverflow.com/questions/56319137/why-does-a-graphql-query-return-null – Preston Jul 29 '19 at 16:55
  • Assuming you're not seeing any errors in the response, it's likely to be an issue with your `express-graphql` configuration. If I had to guess, I'd say you're using `buildSchema` (which you [probably shouldn't be doing](https://stackoverflow.com/questions/53984094/notable-differences-between-buildschema-and-graphqlschema/53987189#53987189)) and not passing in the `rootValue` correctly. Please update your question to include your server config. – Daniel Rearden Jul 29 '19 at 17:56
  • thanks for intended help.I have solved the issue.it was minor mistype. – Manish Bhatti Jul 29 '19 at 18:39

0 Answers0