Skip to content

Instantly share code, notes, and snippets.

@JakeDawkins
Last active October 5, 2018 17:13
Show Gist options
  • Select an option

  • Save JakeDawkins/9046ec0bc65e92b759cc0b39bff62ef3 to your computer and use it in GitHub Desktop.

Select an option

Save JakeDawkins/9046ec0bc65e92b759cc0b39bff62ef3 to your computer and use it in GitHub Desktop.
context: ({ req }) => {
// get the user token from the headers
const token = req.headers.authentication || '';
// try to retrieve a user with the token
const user = getUser(token);
// optionally block the user
// we could also check user roles/permissions here
if (!user) throw new AuthenticationError('you must be logged in to query this schema');
// add the user to the context
return {
user,
models: {
User: generateUserModel({ user }),
...
}
};
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment