chukwuyem

Server

Nov 17th, 2020
468
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Meteor } from "meteor/meteor";
  2. import { makeExecutableSchema } from "graphql-tools";
  3. import { createApolloServer } from "meteor/apollo";
  4.  
  5. import { setup } from "meteor/swydo:ddp-apollo";
  6. import ResolutionsSchema from "../../api/resolutions/Resolutions.graphql";
  7. import ResolutionsResolvers from "../../api/resolutions/resolvers";
  8. import UsersSchema from "../../api/Users/User.graphql";
  9. import UsersResolvers from "../../api/Users/resolvers";
  10.  
  11. import { WebApp } from "meteor/webapp";
  12. import { getUser } from "meteor/apollo";
  13. import merge from "lodash/merge";
  14. import { ApolloServer, gql } from "apollo-server-express";
  15. //qqsq
  16.  
  17. const typeDefs = [ResolutionsSchema, UsersSchema];
  18.  
  19. const resolvers = merge(ResolutionsResolvers, UsersResolvers);
  20.  
  21. const server = new ApolloServer({
  22.   typeDefs,
  23.   resolvers,
  24.   context: async ({ req }) => ({
  25.     user: await getUser(req.headers.authorization),
  26.   }),
  27. });
  28.  
  29. server.applyMiddleware({
  30.   app: WebApp.connectHandlers,
  31.   path: "/graphql",
  32. });
  33.  
  34. WebApp.connectHandlers.use("/graphql", (req, res) => {
  35.   if (req.method === "GET") {
  36.     res.end();
  37.   }
  38. });
  39.  
RAW Paste Data