NestJS에서 GraphQL 사용하기

roglog·2021년 3월 26일
0

Apollo Server Setup

  • nestJs의 graphQL은 apollo-server-express를 기반하여 작동한다.
  • setting
    npm i @nestjs/graphql graphql-tools graphql apollo-server-express
  • app.module.ts
    import { GraphQLModule } from '@nestjs/graphql';

    @Module({
      imports: [GraphQLModule.forRoot({
        autoSchemaFile: true,
      })],
      controllers: [],
      providers: [],
    })
    export class AppModule {}

Validation ArgsType

  • Ex) @IsString, @Length ...
  • setting
    npm i class-validator class-transformer
  • main.ts
    import { ValidationPipe } from '@nestjs/common';

    async function bootstrap() {
      app.useGlobalPipes(new ValidationPipe());
    }
    bootstrap();
profile
Full Stack Developer 📚

0개의 댓글