// graphql.js

import { ApolloServer } from "apollo-server-lambda";
import resolvers from "../resolvers/public";
import definitions from "../schema/public.gql";

const server = new ApolloServer({
  context: ({ event, context }) => ({
    context,
    event,
    functionName: context.functionName,
    headers: event.headers,
  }),
  introspection: true,
  playground: true,
  resolvers,
  typeDefs: definitions,
});

export const handler = server.createHandler({
  cors: {
    credentials: true,
    origin: true,
  },
});
