본문 바로가기

Uber Eats

Uber Eats # 2 graphql

graphql document를 참고해서 설치하기

 

$ npm i @nestjs/graphql graphql-tools graphql apollo-server-express

graphql과 apollo-server-express로 동작

 

app.module.ts를 제외하고 나머지 삭제(app.controller.spec.ts, app.controller.ts, app.service.ts)

app.module은 main.ts에서 import되는 유일한 모듈이다. main.ts는 application을 실행해준다. 

NestFactory가 AppModule로부터 application을 생성한다. 따라서 AppModule이 데이터베이스를 가져오고 GraphQL 등등을 다 가져온다. 

 

GraphQL 모듈을 AppModule에 넣어준다.

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';

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

forRoot()는 rootModule을 설정한다. 여기서는 GraphQL이 root에 해당한다.

 

이후 실행 시 에러를 만난다.

 Error: Apollo Server requires either an existing schema, modules or typeDef

GraphQL을 실행하려면 resolver, schema 등이 있어야 하는데 없어서 나는 에러이다.

 

다음 장에서 살펴보도록 하자.

'Uber Eats' 카테고리의 다른 글

Uber Eats # 4 entity ObjectType  (0) 2021.03.06
Uber Eats # 3 Apollo server  (0) 2021.03.06
Uber Eats # 1 nest, gitignore, github  (0) 2021.03.06
# 3-1 NestJS - 구조 파악하기  (0) 2021.02.11
# 3-0 Nest.js  (0) 2021.02.11