Skip to content

Instantly share code, notes, and snippets.

@kulakowka
Created November 24, 2018 21:00
Show Gist options
  • Save kulakowka/8f616178c89f22728c8ffbcb0fef3e90 to your computer and use it in GitHub Desktop.
Save kulakowka/8f616178c89f22728c8ffbcb0fef3e90 to your computer and use it in GitHub Desktop.
const {
ApolloServer,
ForbiddenError,
AuthenticationError,
UserInputError
} = require("apollo-server-express");
const requireDirectory = require("require-directory");
const { readFileSync } = require("fs");
const db = require("../db");
const resolvers = requireDirectory(module, "./resolvers");
const typeDefs = readFileSync(__dirname + "/schema.graphql", "utf8");
const errors = {
ForbiddenError,
AuthenticationError,
UserInputError
};
const server = new ApolloServer({
typeDefs,
resolvers,
context: async ({ req }) => ({
viewer: await db.User.findByToken(req.headers.authorization),
db,
errors
})
});
module.exports = server;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment