-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapollo-server.js
More file actions
50 lines (43 loc) · 918 Bytes
/
apollo-server.js
File metadata and controls
50 lines (43 loc) · 918 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { ApolloServer, gql } = require('apollo-server-lambda');
const books = [
{
title: 'Harry Potter and the Chamber of Secrets',
author: 'J.K. Rowling',
},
{
title: 'Jurassic Park',
author: 'Michael Crichton',
},
];
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Book {
title: String
author: String
}
type Query {
hello: String
books: [Book]
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: (root, args, context) => `
Hello world!
Available context: ${Reflect.ownKeys(context)}
`,
books: () => books
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ event, context }) => ({
headers: event.headers,
functionName: context.functionName,
event,
context,
}),
});
exports.handler = server.createHandler();