-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (35 loc) · 961 Bytes
/
index.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
require("dotenv").config();
const { ApolloServer } = require("apollo-server-lambda");
const { ApolloServer: ApolloServerLocal } = require("apollo-server");
const schema = require("./graphql/federation");
const { verify } = require("@pointblankdev/lambda-auth");
const environment = process.env.ENV;
if (environment === "local") {
// Local development
const server = new ApolloServerLocal({ schema });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
} else {
// AWS Lambda
const server = new ApolloServer({
schema,
context: ({ event, context }) => ({
headers: event.headers,
functionName: context.functionName,
event,
context,
user: verify(event),
}),
playground: {
endpoint: `/${environment}/graphql`,
},
introspection: true,
});
exports.handler = server.createHandler({
cors: {
origin: "*",
credentials: false,
},
});
}