From 574d81aa1642576bdc5cc0bc559d9836c2836631 Mon Sep 17 00:00:00 2001 From: Duncan Chen Date: Mon, 30 Dec 2019 15:39:37 -0600 Subject: [PATCH] docs: Example for integration-specific `context` args. (#3455) * 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 --- docs/source/security/authentication.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/source/security/authentication.md b/docs/source/security/authentication.md index 82fc4575577..674381c5334 100644 --- a/docs/source/security/authentication.md +++ b/docs/source/security/authentication.md @@ -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 }; },