text: const { AuthenticationError } = require('apollo-server-express');
  // import user model
  const { User } = require('../models');
  const { signToken } = require('../utils/auth');
  
  const resolvers = {
    Query: {
      // By adding context to our query, we can retrieve the logged in user without specifically searching for them
      me: async (parent, args, context) => {
        if (context.user) {
          return User.findOne({ _id: context.user._id });
        }
        throw new AuthenticationError('You need to be logged in!');
      },
    },
  
    Mutation: {
      /*createUser: async (parent, { name, email, password }) => {
        const profile = await Profile.create({ name, email, password });
        const token = signToken(profile);
  
        return { token, profile };
      },*/
      login: async (parent, { email, password }) => {
        const profile = await Profile.findOne({ email });
  
        if (!profile) {
          throw new AuthenticationError('No profile with this email found!');
        }
  
        const correctPw = await profile.isCorrectPassword(password);
  
        if (!correctPw) {
          throw new AuthenticationError('Incorrect password!');
        }
  
        const token = signToken(profile);
        return { token, profile };
      },
    },
  };
  
  module.exports = resolvers;
  