text: const bcrypt = require('bcryptjs')
  const jwt = require('jsonwebtoken')
  
  const auth = {
    async signup(parent, args, ctx, info) {
      const password = await bcrypt.hash(args.password, 10)
      const user = await ctx.db.mutation.createUser({
        data: { ...args, password },
      })
  
      return {
        token: jwt.sign({ userId: user.id }, 'secret123'),
        user,
      }
    },
  
    async login(parent, { email, password }, ctx, info) {
      const user = await ctx.db.query.user({ where: { email } })
      if (!user) {
        return {
          token: null,
          user: null,
          error: "Invalid!"
        }
      }
  
      const valid = await bcrypt.compare(password, user.password)
      if (!valid) {
        throw new Error('Invalid password')
      }
  
      return {
        token: jwt.sign({ userId: user.id }, 'secret123'),
        user,
      }
    },
  }
  
  module.exports = { auth }