카테고리 없음 2020. 2. 21. 11:37

graphql-yoga를 이용해 서버를 세우고,

그 다음에 prisma를 서버 코드에 추가할 계획( what is prisma?)

graphql-yoga는 graphql서버를 쉽게 설치하게 도와줌. 

https://github.com/prisma-labs/graphql-yoga

 

prisma-labs/graphql-yoga

🧘 Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience - prisma-labs/graphql-yoga

github.com

.babelrc파일을 추가하고 아래처럼 작성,

yarn add @babel/{node,preset-env,core}

위 두 작업을 하지 않으면 import인식 에러뜸

 

dotenv 모듈을 설치하자. dotenv모듈은 .env 파일을 읽는다.

yarn add dotenv

 

src/server.js파일을 아래와 같이 작성한다.

 

서버를 만들때 GraphQLServer()를 이용한다 이때 파라미터로

typeDef와 resolver들이 필요함. 

 

dotenv config 에서 포트를 읽어오게 할 수 있다. 

.env파일에 PORT를 추가하자. 

 

yarn dev를 실행하면 

콘솔 로그 가 출력되는것을 볼 수 있따.

***만약 Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3".  에러 발생시 

    yarn remove babel-cli 를 해주도록 하자 ***

posted by LotzBurger
: