yarn init
yarn add graphql-yoga
express 는 필요없음
yarn add nodemon -D
package.json
"scripts": { "deploy": "prisma deploy", "generate": "prisma generate", "prisma": "yarn run deploy && yarn run generate", "dev": "nodemon --exec babel-node src/server.js" }
yarn add babel-node
yarn add babel-cli
nodemon.json
{ "ext": "js graphql" }
yarn add dotenv
yarn @babel/{node,preset-env}
yarn @babel/core
.babelrc
{ "presets": ["@babel/preset-env"] }
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}`) );
yarn graphql-tools merge-graphql-schemas
폴더 구조를 잡아줌, 경로에 있는 모든 graphql, js 파일을 읽어서 한 곳에 모아줌
src/api/Greetings/sayHello/sayHello.graphql
type Query { sayHello: String! }
src/api/Greetings/sayHello/sayHello.js
export default { Query: { sayHello: () => "Hello" } };
src/schema.js
import path from "path"; import { makeExecutableSchema } from "graphql-tools"; import { fileLoader, mergeResolvers, mergeTypes } from "merge-graphql-schemas"; const allTypes = fileLoader(path.join(__dirname, "/api/**/*.graphql")); const allResolvers = fileLoader(path.join(__dirname, "/api/**/*.js")); const schema = makeExecutableSchema({ typeDefs: mergeTypes(allTypes), resolvers: mergeResolvers(allResolvers) }); export default schema;
'미분류' 카테고리의 다른 글
Hooks + Apollo 초기 세팅 (0) | 2019.07.31 |
---|---|
prisma 알게 된 것들 (0) | 2019.07.30 |
datamodel.prisma 예시 (0) | 2019.07.30 |