// server.js// 패키지 가져오기const{ loadFilesSync }=require("@graphql-tools/load-files");// loadFilesSync로 현재 폴더(__dirname)에 있는 모든 폴더(**) 속의// graphql 확장자로 끝나는 모든 파일(*) 불러오기const loadedTypes =loadFilesSync('**/*',{extensions:['graphql'],});const schema =makeExecutableSchema({typeDefs: loadedTypes
});
1-2. value 분리
현재 rootValue 하나에 데이터 값이 모두 보관되어 있는데 이를 분리하기
- 데이터 소스코드 나눠주기 (모듈화 하기)
comments/comments.model.js 파일 생성
posts/posts.model.js 파일 생성
// server.js의 기존 데이터const root ={posts:[{id:"post1",title:"It is a first post",description:"It is a first post description",comments:[{id:"comment1",text:"It is a first comment",likes:1,},],},{id:"post2",title:"It is a second post",description:"It is a second post description",comments:[],},],comments:[{id:"comment1",text:"It is a first comment",likes:1,},],};
위의 데이터 코드를 각각 분리하여 작성
module.exports를 통해 내보내기
// posts/posts.model.js
module.exports =[{id:"post1",title:"It is a first post",description:"It is a first post description",comments:[{id:"comment1",text:"It is a first comment",likes:1,},],},{id:"post2",title:"It is a second post",description:"It is a second post description",comments:[],},];
// comments/comments.model.js
module.exports =[{id:"comment1",text:"It is a first comment",likes:1,},];