chukwuyem

Apollo server

Dec 12th, 2020
638
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { ApolloServer } from "apollo-server-micro";
  2. import { schema } from "../../src/schema.ts";
  3. import { createContext } from "../../src/context.ts";
  4. const jwt = require("jsonwebtoken");
  5.  
  6. const server = new ApolloServer({
  7.   schema,
  8.   // context: ({ req }) => {
  9.   //   try {
  10.   //     const token = req.header.authorization;
  11.   //     if (!token) {
  12.   //       return {
  13.   //         user: null,
  14.   //         createContext,
  15.   //       };
  16.   //       const decoded = jwt(token.slice(7), process.env.JWT_SECRET);
  17.   //       return { user: decoded };
  18.   //     }
  19.   //   } catch (err) {
  20.   //     return { user: null, createContext };
  21.   //   }
  22.   // },
  23.  
  24.   context: createContext,
  25.   tracing: process.env.NODE_ENV === "development",
  26. });
  27. const handler = server.createHandler({ path: "/api/graphql" });
  28.  
  29. export const config = {
  30.   api: {
  31.     bodyParser: false,
  32.   },
  33. };
  34.  
  35. export default handler;
  36.  
RAW Paste Data