Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

SameerDoshi
Copy link

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.

@apollo-cla
Copy link

@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/

Copy link
Member

@glasser glasser left a 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.
Copy link
Member

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 || '';
Copy link
Member

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');
Copy link
Member

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.
Copy link
Member

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".

@rkoron007 rkoron007 added the 📝 documentation Focuses on changes to the documentation (docs) label Jun 29, 2022
@trevor-scheer
Copy link
Member

trevor-scheer commented Oct 18, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📝 documentation Focuses on changes to the documentation (docs)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants