Created
June 12, 2018 19:11
-
-
Save daniele-zurico/ff53e986163a71b284efecf40db6800c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| export const pubsub = new PubSub(); | |
| const MONGO_PORT = 27017; | |
| const MONGO_URL = "localhost"; | |
| const dbName = "graphExample"; | |
| export const CLIENT_ID = | |
| "YOUR_ID"; | |
| export const client = new OAuth2Client(CLIENT_ID); | |
| // help to debug mongoose | |
| mongoose.set("debug", true); | |
| mongoose.connect(`mongodb://${MONGO_URL}:${MONGO_PORT}/${dbName}`); | |
| const schema: GraphQLSchema = mergeSchemas({ | |
| schemas, | |
| resolvers | |
| }); | |
| // GraphQL | |
| const server = new ApolloServer({ | |
| schema, | |
| context: async ({ req }: any) => { | |
| if (!req || !req.headers) { | |
| return; | |
| } | |
| const token = req.headers.authorization || ""; | |
| const checkToken = await userController.findOrCreateUser(token); | |
| if (!checkToken.hasOwnProperty('authorized')) { | |
| return {user: checkToken, authorized: true}; | |
| } | |
| return checkToken; | |
| }, | |
| tracing: true, | |
| }); | |
| server.listen().then(({ url }) => { | |
| console.log(`🚀 Server ready at ${url}`); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment