-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation: Azure Functions Deployment #5675
Conversation
…loying Apollo Server in an Azure function.
@SameerDoshi: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, I'd suggest we focus more on our docs site and less on the individual package READMEs instead of having two separate places to look for information.
https://www.apollographql.com/docs/apollo-server/deployment/azure-functions/ is the docs page, with source at docs/source/deployment/azure-functions.md
. The Lambda docs page has a nice section on this sort of thing that could be copied and adapted into the Azure section.
@@ -138,6 +138,26 @@ The options correspond to the [express cors configuration](https://github.com/ex | |||
* `credentials`: boolean | |||
* `maxAge`: number | |||
|
|||
### Request Body / Token | |||
By default Azure Functions will pass the request object as req. Pass this into the context of the ApolloServer constructor to access request contents. For example for passing an auth token to a backend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
req is just the name you're choosing for an argument here, FWIW.
{ typeDefs, | ||
resolvers, | ||
context: (req) => { | ||
const authHeader = req.context.bindings.req.headers.authorization || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that actually the best way to get a header? I see at https://www.apollographql.com/docs/apollo-server/api/apollo-server/#middleware-specific-context-fields that we pass context
and also request
. Wouldn't req.request.headers
be simpler?
resolvers, | ||
context: (req) => { | ||
const authHeader = req.context.bindings.req.headers.authorization || ''; | ||
if (authHeader === '') throw new AuthenticationError('please send Bearer token with request'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird spacing in the error message
``` | ||
|
||
### Optional, helpful packages | ||
* azure-function-log-intercept - console.* messages appear in teh functions log. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how helpful this is without an example of how to use it. Also typo "teh" vs "the".
Going to close this since it's no longer mergeable / we don't have an azure integration that we maintain in this repo anymore. I've captured it in a separate issue here which is concerned with providing getting started guides for serverless applications. |
Adding additional documentation on accessing request headers when dep…loying Apollo Server in an Azure function.
Big picture: Running Apollo in an Azure Function where Apollo access protected backend APIs a user might want to pass a user provided token to the backend API.