/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sample/31-graphql-federation-code-first/posts-application/src/posts/posts.resolver.ts
32 строки
771 B
yiminghe
fix(sample): id param is string type
18 май 2022, 17:55
18 май 2022, 17:55
477303b
Код
Авторство
О чём код?
import { Args, ID, Parent, Query, ResolveField, Resolver, } from '@nestjs/graphql'; import { Post } from './models/post.model'; import { User } from './models/user.model'; import { PostsService } from './posts.service'; import { ParseIntPipe } from '@nestjs/common'; @Resolver((of) => Post) export class PostsResolver { constructor(private readonly postsService: PostsService) {} @Query((returns) => Post) post(@Args({ name: 'id', type: () => ID }, ParseIntPipe) id: number): Post { return this.postsService.findOne(id); } @Query((returns) => [Post]) posts(): Post[] { return this.postsService.findAll(); } @ResolveField((of) => User) user(@Parent() post: Post): any { return { __typename: 'User', id: post.authorId }; } }