-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (34 loc) · 658 Bytes
/
index.js
File metadata and controls
36 lines (34 loc) · 658 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const {gql,ApolloServer} = require("apollo-server")
const typeDefs =`
type Book{
title: String
author: String
id: ID
}
type Query{
books: [Book]
book(id: ID!): Book
}
`
const resolvers={
Query: {
books: ()=>books,
book: (_, { id }) => books.find((book) => book.id == id),
}
}
const books = [
{
title: 'Harry Potter and the Chamber of Secrets',
author: 'J.K. Rowling',
id: 1
},
{
title: 'Jurassic Park',
author: 'Michael Crichton',
id: 2
},
];
const server = new ApolloServer({typeDefs,resolvers});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});