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

Add per request global context #1789

Merged
merged 14 commits into from
Mar 5, 2021
Merged

Add per request global context #1789

merged 14 commits into from
Mar 5, 2021

Conversation

peterp
Copy link
Contributor

@peterp peterp commented Feb 13, 2021

This adds the experimental NodsJS async local storage API so that we can have a per-request global context.

  • Add tests

@github-actions
Copy link

github-actions bot commented Feb 13, 2021

📦 PR Packages

Click to Show Package Download Links

https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/create-redwood-app-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-api-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-api-server-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-auth-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-cli-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-core-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-dev-server-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-eslint-config-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-eslint-plugin-redwood-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-forms-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-internal-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-prerender-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-router-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-structure-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-testing-0.26.2-ed28c09.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/1789/redwoodjs-web-0.26.2-ed28c09.tgz

Install this PR by running yarn rw upgrade --pr 1789:0.26.2-ed28c09

Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
@peterp peterp marked this pull request as ready for review March 2, 2021 18:54
@cypress
Copy link

cypress bot commented Mar 4, 2021



Test summary

8 0 0 0


Run details

Project RedwoodJS Framework
Status Passed
Commit 9551912 ℹ️
Started Mar 5, 2021 2:14 PM
Ended Mar 5, 2021 2:16 PM
Duration 01:38 💡
OS Linux Ubuntu - 16.04
Browser Chrome 88

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

packages/api/src/globalContext.ts Outdated Show resolved Hide resolved
packages/api/src/globalContext.ts Outdated Show resolved Hide resolved
packages/api/src/functions/graphql.ts Outdated Show resolved Hide resolved
packages/api/src/globalContext.ts Show resolved Hide resolved
packages/api/src/functions/graphql.test.ts Outdated Show resolved Hide resolved
| AsyncLocalStorage<Map<string, GlobalContext>> = undefined

export const usePerRequestContext = () =>
process.env.SAFE_GLOBAL_CONTEXT !== '1'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set this to '1' in the netlify and vercel deploy setup scripts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - because there is a performance impact, but I'm not 100% certain that I want to trust Netlify and Vercel. So I would like to make this the default everywhere, and give people the ability to opt-out with the understand that it could be a problem.

peterp and others added 2 commits March 5, 2021 15:33
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
@peterp peterp added this to the next release milestone Mar 5, 2021
@peterp peterp merged commit 148aa46 into main Mar 5, 2021
@thedavidprice thedavidprice deleted the pp-per-request-context branch March 5, 2021 17:10
@thedavidprice
Copy link
Contributor

So I would like to make this the default everywhere, and give people the ability to opt-out with the understanding that it could be a problem.

@peterp @Tobbe we definitely need some documentation about all this. Maybe we expand this doc to be API & Serverless Functions... https://redwoodjs.com/docs/serverless-functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants