Skip to content

Commit

Permalink
docs: Example for integration-specific context args. (#3455)
Browse files Browse the repository at this point in the history
* Update authentication.md

I follow this example on Azure Function and it failed. After a little digging, I found out the req object is passed as "request". There may be some inconsistency in implementation.

* Adjust #3455 to account for new content in #3506.

This should hopefully make it more clear what information is available on
the argument to `context`, and how it might need to be adjusted for each
specific integration.

Co-authored-by: Jesse Rosenberger <git@jro.cc>
  • Loading branch information
duncanchen and abernix committed Dec 30, 2019
1 parent 6bf16d4 commit 574d81a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docs/source/security/authentication.md
Expand Up @@ -23,12 +23,20 @@ const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => {
// get the user token from the headers
// Note! This example uses the `req` object to access headers,
// but the arguments received by `context` vary by integration.
// This means they will vary for Express, Koa, Lambda, etc.!
//
// To find out the correct arguments for a specific integration,
// see the `context` option in the API reference for `apollo-server`:
// https://www.apollographql.com/docs/apollo-server/api/apollo-server/

// 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 };
},
Expand Down

0 comments on commit 574d81a

Please sign in to comment.