-
#1.1 Creating GraphQL Server개발 2019. 5. 8. 00:59
prisma를 시작히기 전에 터미널에 'yarn add dotenv'를 실행한다.
서버를 먼저 세우고, 그 다음에 primsa 서버 코드를 추가한다.
dotenv 모듈 설치
여러가지 환경 설정 파일을 관리하는 패키지로 .env 파일에 설정값을 보관하고
해당 값을 필요한 시점에 가져올 수 있는 역할을 수행한다.
> yarn add dotenv src 폴더에 .env 파일을 생성하고 Port 와 같은 Application 전체에서 사용이 필요한 환경 변수를 입력함.
GraphQL Sever 생성
server.js 파일에 아래와 같이 코드를 입력함.
require("dotenv").config(); import { GraphQLServer } from "graphql-yoga"; const PORT = process.env.PORT || 4000; const typeDefs = ` type Query{ hello: String! } `; const resolvers = { Query: { hello: () => "Hi" } }; const server = new GraphQLServer({ typeDefs, resolvers }); server.start({ port: PORT }, () => console.log(`Server running on http://localhost:${PORT}`) );
babel 패키지 설치
bebel은 javascript 컴파일러로 이를 통해 브라우저에서 이해하지 못하는 최신 ES6, ES7 문법을 사용하여
개발을 할 수 있게 된다.
https://medium.com/@ljs0705/babel-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0-a1d0e6bd021a
Babel 이해하기
react로 개발을 하고 있다면 거의 대부분 babel도 함께 사용하고 있을 것이다. create-react-app에도 기본으로 들어있고 기타 react 관련된 튜토리얼을 따라 하다 보면 자연스럽게 babel을 설치하게 된다. 굳이 react가…
medium.com
우선 필요한 bebel 패키지에 대한 설치가 필요하다.
> yarn add @babel/core
> yarn addd @babel/node
> yarn add @babel/preset-env설치 후 실행 시, 아래와 같은 메시지가 나오는 경우, babel-cli를 삭제해야 함. (yarn remove babel-cli)
Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version.
.babelrc 파일을 생성한 후 아래와 같이 입력함.
{ "presets": ["@babel/preset-env"] }
'개발' 카테고리의 다른 글
[독서] 5:5:5 코딩 교육 (0) 2019.10.27 패스워드 관련 정규표현식 (0) 2019.08.31 Node.js - 비동기 함수에서 순차 처리 (async/await) (0) 2019.06.08 Protopie로 SmartThings 제어 프로토 타입 만들기 (0) 2019.06.07 #1.0. Setting up the project (0) 2019.05.07