import { Arg, Mutation, Resolver } from 'type-graphql'; import { v4 } from 'uuid'; import { Lead } from '../../entities'; import { AddLeadInput, AddLeadResponse } from './types'; @Resolver(Lead) export class LeadResolver { @Mutation(() => AddLeadResponse) async addLead( @Arg('input') input: AddLeadInput ): Promise { const { email } = input; const id = v4(); const lead = (await Lead.findOne({ email, })) ?? (await Lead.create({ id, firebaseId: id, email, }).save()); return { lead, success: true, }; } }