-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(context): Refactor context #9371
Conversation
Testing again with k6 tests shows that context works for the following:
The p(90) of the request durations where also pretty much the same before and after the changes added here. Of course this is all local and not results from deployed apps. How to test?
This should all be possible with the |
@Tobbe and I discussed this PR and the suggestion was that we attempt to make this not breaking. We restore the original files in the I can't guarantee it is not breaking for people who have used our context related code within their own app in an attempt to get context working outside graphql. In this case they should be able to fix any issues by removing their custom code and relying on the functionality now being provided by the framework. |
…redwood into fix/enhance-error-apollo-suspense * 'fix/enhance-error-apollo-suspense' of github.com:dac09/redwood: (92 commits) chore(deps): update dependency @types/yargs to v17.0.32 (redwoodjs#9759) Make it easier to find useMatch docs (redwoodjs#9756) chore(unit tests): Use side-effect import to fix TS errors (redwoodjs#9754) fix(context): Refactor context (redwoodjs#9371) docs: Replaced deprecated <Set private> with PrivateSet within router.md (redwoodjs#9749) add TS support for storybook preview tsx config extension (redwoodjs#9309) fix(studio): Fix windows path issues (redwoodjs#9752) redwoodjs#9620: Update studio to support variable components (Mailer) (redwoodjs#9639) chore(tasks): Add comparison view to nmHoisting visualisation (redwoodjs#9751) chore(cli): make fs modules used in the CLI consistent (redwoodjs#9746) chore(tooling): Make sure console boxen print on a new line chore(CI): fix publish release candidate feat(CLI): add check node version middleware, rm `.nvmrc`, yarn engines (redwoodjs#9728) docs: added some clarification on serverless functions getting executed in a non-serverless environment (redwoodjs#9742) Fix sshExec() errors not displaying (redwoodjs#9743) chore(tooling): Add missing word in release tooling output Update Metadata docs (redwoodjs#9744) chore(CI): update test project fixture and CRWA for deploy target CI repo (redwoodjs#9730) chore(tooling): add script for getting nested dependency data (redwoodjs#9734) Trusted Documents docs: Proofreading corrections (redwoodjs#9737) ...
…ath-aliases * 'main' of github.com:redwoodjs/redwood: (92 commits) chore(deps): update dependency @types/yargs to v17.0.32 (redwoodjs#9759) Make it easier to find useMatch docs (redwoodjs#9756) chore(unit tests): Use side-effect import to fix TS errors (redwoodjs#9754) fix(context): Refactor context (redwoodjs#9371) docs: Replaced deprecated <Set private> with PrivateSet within router.md (redwoodjs#9749) add TS support for storybook preview tsx config extension (redwoodjs#9309) fix(studio): Fix windows path issues (redwoodjs#9752) redwoodjs#9620: Update studio to support variable components (Mailer) (redwoodjs#9639) chore(tasks): Add comparison view to nmHoisting visualisation (redwoodjs#9751) chore(cli): make fs modules used in the CLI consistent (redwoodjs#9746) chore(tooling): Make sure console boxen print on a new line chore(CI): fix publish release candidate feat(CLI): add check node version middleware, rm `.nvmrc`, yarn engines (redwoodjs#9728) docs: added some clarification on serverless functions getting executed in a non-serverless environment (redwoodjs#9742) Fix sshExec() errors not displaying (redwoodjs#9743) chore(tooling): Add missing word in release tooling output Update Metadata docs (redwoodjs#9744) chore(CI): update test project fixture and CRWA for deploy target CI repo (redwoodjs#9730) chore(tooling): add script for getting nested dependency data (redwoodjs#9734) Trusted Documents docs: Proofreading corrections (redwoodjs#9737) ...
…p-prebuild * 'main' of github.com:redwoodjs/redwood: (1608 commits) Docker: Update to work with corepack and yarn v4 (redwoodjs#9764) [RFC]: useRoutePaths (redwoodjs#9755) Adds a note about the two commands you will use with your schema to the top of the schema file (redwoodjs#8589) docs: Supertokens.md: Fix typo (redwoodjs#9765) Fix supertokens docs & integration issues (redwoodjs#9757) fix(apollo): Enhance error differently for Suspense Cells (redwoodjs#9640) SSR smoke-test: Use <Metadata /> (redwoodjs#9763) chore(deps): update dependency @types/qs to v6.9.11 (redwoodjs#9761) chore(ci): Better error handling in detectChanges.mjs (redwoodjs#9762) fix(path-alias): Fix aliasing of paths using ts/jsconfig (redwoodjs#9574) chore(deps): update dependency @types/yargs to v17.0.32 (redwoodjs#9759) Make it easier to find useMatch docs (redwoodjs#9756) chore(unit tests): Use side-effect import to fix TS errors (redwoodjs#9754) fix(context): Refactor context (redwoodjs#9371) docs: Replaced deprecated <Set private> with PrivateSet within router.md (redwoodjs#9749) add TS support for storybook preview tsx config extension (redwoodjs#9309) fix(studio): Fix windows path issues (redwoodjs#9752) chore(tasks): Add comparison view to nmHoisting visualisation (redwoodjs#9751) chore(cli): make fs modules used in the CLI consistent (redwoodjs#9746) ...
Co-authored-by: Tobbe Lundberg <[email protected]>
Problem
Context isolation was partially updated in v6 to remove a legacy flag which allowed disabling of context isolation. This unfortunately introduced some bugs for users which could not be further addressed without more potentially breaking changes. These were mainly centred around users who had introduced their own context isolation/handling into non-graphql functions.
Functions (other than graphql) have never had the assurance of context isolation out of the box - even though we allow direct access to the context in a function like we do in other places such as services. This is clear when you look at the results of k6 tests which test context isolation:
I do not think this is behaviour we should support. It is a confusing disparity in behaviour between graphql and other functions.
Changes
@redwoodjs/context
. This is to avoid circular dependencies when it lives in either@redwoodjs/api-server
or@redwoodjs/graphql-server
. It is also a small package with no external dependencies which also helps to avoid bringing in unneeded code should it live in somewhere like@redwoodjs/api
- although I am happy to move this into that package should we feel it'll only ever be used in conjunction with it.getAsyncStoreInstance
function as a dist import to discourage direct usage by users.TODO
GlobalContext
to something more descriptive likeRedwoodAPIContext
or similar.^ The refactoring TODOs might not make it in here.