-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.js
85 lines (81 loc) · 1.67 KB
/
handler.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import 'babel-polyfill';
const { ApolloServer, gql } = require('apollo-server-lambda');
const { DynamoDBCache } = require('./dynamoCache');
const typeDefs = gql`
type Todo @cacheControl(maxAge: 120){
id: String!
content: String!
}
type Query {
todo(id: String!): Todo
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
todo: async (_, { id }, { }) => {
switch (id) {
case "1":
return {
id: id,
content: "HAHA1"
}
default:
return {
id: id,
content: "HAHAX"
}
}
}
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
tracing: true,
cacheControl: {
defaultMaxAge: 5,
stripFormattedExtensions: false,
calculateCacheControlHeaders: false,
},
persistedQueries: {
cache: new DynamoDBCache({
region: 'us-east-1',
endpoint:
process.env.IS_OFFLINE==='true'
?
'http://localhost:8000'
:
''
},
{
tableName: 'psq',
ttl: 0
}
),
},
// cache: new DynamoDBCache({
// region: 'local',
// endpoint:
// process.env.IS_OFFLINE==='true'
// ?
// 'http://localhost:8000'
// :
// ''
// }),
context: ({ event, context }) => ({
headers: event.headers,
functionName: context.functionName,
event,
context,
})
});
exports.graphqlHandler = (event, context, callback) => {
const handler = server.createHandler({
cors: {
origin: '*',
credentials: true,
},
});
return handler(event, context, callback);
}