Skip to content

Instantly share code, notes, and snippets.

@JakeDawkins
Last active May 15, 2018 13:09
Show Gist options
  • Select an option

  • Save JakeDawkins/15aef93fee7383a48dfe017f703bfc8e to your computer and use it in GitHub Desktop.

Select an option

Save JakeDawkins/15aef93fee7383a48dfe017f703bfc8e to your computer and use it in GitHub Desktop.
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