1
import { ApolloServer } from "apollo-server-lambda"
2
import { APIGatewayEvent, Context as LambdaContext } from "aws-lambda"
3
import schema from "./schema"
4
import dataSources from "./sources"
5
import { playground } from "./playground"
6

7
export interface Context {
8
  headers: APIGatewayEvent["headers"]
9
  functionName: LambdaContext["functionName"]
10
  event: APIGatewayEvent
11
  context: LambdaContext
12
}
13

14 1
export const server = new ApolloServer({
15
  schema,
16
  context: ({
17
    event,
18
    context
19
  }: {
20
    event: APIGatewayEvent
21
    context: LambdaContext
22 0
  }): Context => ({
23
    headers: event.headers,
24
    functionName: context.functionName,
25
    event,
26
    context
27
  }),
28
  dataSources,
29
  tracing: true,
30
  formatError: err => {
31
    // eslint-disable-next-line no-console
32 0
    console.error(err)
33 0
    return err
34
  },
35
  introspection: true,
36
  playground
37
})

Read our documentation on viewing source code .

Loading