Created
November 24, 2018 21:00
-
-
Save kulakowka/8f616178c89f22728c8ffbcb0fef3e90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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