generated from ganesh-4212/node-express-graphql-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
author.resolver.ts
30 lines (26 loc) · 996 Bytes
/
author.resolver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Book } from './../models/book.model'
import { BookService } from './../service/book.service'
import { AuthorInput } from './../schema/input-types'
import { AuthorService } from './../service/author.service'
import { Author } from './../models/author.model'
import { Resolver, Query, Arg, Mutation, Root, FieldResolver } from 'type-graphql'
@Resolver(of => Author)
export class AuthorResolver {
constructor(private authorService: AuthorService, private bookService: BookService) {}
@Query(returns => Author, { nullable: true })
author(@Arg('authorId') authorId: string) {
return this.authorService.getById(authorId)
}
@FieldResolver()
books(@Root() author: Partial<Author>) {
return this.bookService.findByAuthorId(author.id)
}
@Query(returns => [Author])
authors() {
return this.authorService.getAll()
}
@Mutation(returns => Author)
async createAuthor(@Arg('author') author: AuthorInput) {
return this.authorService.createAuthor(author)
}
}