Develop/GraphQL

GQL서버 init

안다희 2020. 4. 10. 04:27
728x90

1. init

yarn init

 

2. src/index.ts 생성

 

3. 설치

yarn add @babel/{node,cli,core} nodemon

 

4. package.json

  "scripts": {
    "dev": "nodemon --exec babel-node src/index.ts"
  }

 

5. nodemon.json 파일 생성 (root에)

nodemon이 감시해야 할 파일의 확장자 지정

{
    "ext": "js graphql"
}

 

6. 

yarn add nexus
yarn add graphql

 

 

 

7. import 인식못해서

yarn add @babel/preset-env

 

.babelrc

{

"presets": ["@babel/preset-env"]

}

 

8. 아.. 근데 ts-node로 하는거네 ts는

 

yarn add ts-node -D

yarn add typescript

 

 

 

 

 

9. tsconfig.json

{
  "compilerOptions": {
    "lib": ["ES2016", "esnext.asynciterable", "DOM"],
    "esModuleInterop": true // 이건 path 땜에
  }
}

DOM을 추가해줘야 10의 에러가 안남

 

 

10. 에러

Cannot find name 'console'. Do you need to change your target library

엥 console.log 했는디... 왜 안돼?

tsconfig , lib property add "dom" 하래

 

11. 일단 서버부터 만들어봐

yarn add apollo-server

https://github.com/daheeahn/heart-signal-server/commit/f0910dac81440f0249f490c45518e7859ab74761

 

12. 이제 prisma init (이때 app.prisma.io 에 있어야 함)

create new db - mysql - prisma typescript client

오? 생각보다 일이 쉽게 풀리는데?

 

docker-compose up -d (??? 왜 하는거지)

prisma deploy

prisma generate

 

 

아직 넥서스 잘 모르니까 하던대로 해보자

yarn add prisma-client-lib

 

 

prisma generate

Duplicate "graphql" modules cannot be used at the same time since different

에러

node_m , .lock삭제후 다시 깔기 (난 yarn 써서 package-lock.json 은 아예 삭제 함)

 

https://github.com/howtographql/react-apollo/issues/33

 

resolution로 버전 확정

그러면

prisma generate 는 잘된다.

 

근데 yarn dev 하면 이상해지네,,,,

 

이것저것 전에 하던대로 하면됨~

https://github.com/daheeahn/heart-signal-server/commit/d052341a9104f2937b2f38fe3b497cd1bd810193

 

서버 세팅 완료 · daheeahn/heart-signal-server@d052341

 

github.com

그럼 요렇게 완료 

아직 nexus는 노적용

 

13. 이제 재균에게 배운 서버 배포 해보자!