import { Resolver, Query, Mutation, Arg } from 'type-graphql' import { User } from '../models/User' // import { CreateBookInput } from '../inputs/CreateBookInput' // import { UpdateBookInput } from '../inputs/UpdateBookInput' @Resolver() export class UserResolver { @Query(() => [User]) users(): Promise { return User.find() } @Query(() => User) user(@Arg('id') id: string): Promise { return User.findOne({ where: { id } }) } /* @Mutation(() => User) async createBook(@Arg('data') data: CreateBookInput) { const book = User.create(data) await book.save() return book } @Mutation(() => Book) async updateBook(@Arg('id') id: string, @Arg('data') data: UpdateBookInput) { const book = await Book.findOne({ where: { id } }) if (!book) throw new Error('Book not found!') Object.assign(book, data) await book.save() return book } */ @Mutation(() => Boolean) async deleteUser(@Arg('id') id: string): Promise { const user = await User.findOne({ where: { id } }) if (!user) throw new Error('User not found!') await user.remove() return true } }