const { ApolloServer, gql } = require("apollo-server");
//Define your GraphQL schema
const typeDefs = gql`
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
// NOTE: please do not use any colon " : " or " , "
`;
//Define your data set
const books = [
{
title: "The Awakening",
author: "Kate Chopin",
},
{
title: "City of Glass",
author: "Paul Auster",
},
];
//Define a resolver
const resolvers = {
Query: {
books: () => {
return [books];
},
},
};
// Apollo Server
const server = new ApolloServer({
typeDefs,
resolvers,
});
server.listen().then(({ url }) => {
console.log(`server ready at ${url}`);
});