const { ApolloServer, gql } = require('apollo-server');
const { readFileSync } = require('fs')
const {join} = require('path')
// The GraphQL schema
const typeDefs = gql`
type Query {
hello: String,
books:[Book],
},
type Book {
bookId: Int,
title: String,
message: String,
author: String,
url: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => 'Hello World',
books: () => {
return JSON.parse(readFileSync(join(__dirname, "books.json")).toString());
},
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
playground:true,
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
[
{
"bookId": 1,
"title": "test",
"message": "message test",
"author": "author test",
"url": "url test"
}
]
처음 배우는 거라 뭐가 뭔지 잘 모르겠지만 조금씩 요청과 응답 작성방법이 이해가 가는 것 같네요.