Good day.
I wrote a small application using typeorm + typegraphql + typescript. It works and everything seems to be fine.
the essence of the problem is that it is not possible to understand the invention for testing ... I understand that you need to connect to the database and run a couple of mutations, and basically everything ...
The documentation could not find the correct connections to resolvers
import {
Resolver,
Mutation,
Arg,
Int,
Query,
} from "type-graphql";
import { Author } from "../entity/Author";
import { AuthorBook } from "../entity/AuthorBook";
import { Book } from "../entity/Book";
@Resolver()
export class AuthorBookResolver {
@Mutation(() => Book)
async createBook(
@Arg("name") name: string,
@Arg("pageCount") pageCount: number,
) {
return Book.create({ name, pageCount }).save();
}
@Mutation(() => Author)
async createAuthor(@Arg("name") name: string) {
return Author.create({ name }).save();
}
@Mutation(() => Boolean)
async addAuthorBook(
@Arg("authorId", () => Int) authorId: number,
@Arg("bookId", () => Int) bookId: number
) {
await AuthorBook.create({ authorId, bookId }).save();
return true;
}
@Mutation(() => Boolean)
async deleteBook(@Arg("bookId", () => Int) bookId: number) {
await AuthorBook.delete({ bookId });
await Book.delete({ bookId });
return true;
}
@Query(() => [Book])
async books() {
return Book.find();
}
}