Last active
May 15, 2018 13:09
-
-
Save JakeDawkins/15aef93fee7383a48dfe017f703bfc8e 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
| const { ApolloServer } = require('apollo-server'); | |
| const server = new ApolloServer({ | |
| typeDefs, | |
| resolvers, | |
| context: ({ req }) => { | |
| // get the user token from the headers | |
| const token = req.headers.authorization || ''; | |
| // try to retrieve a user with the token | |
| const user = getUser(token); | |
| // add the user to the context | |
| return { user }; | |
| }, | |
| }); | |
| 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