-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: require explicit query context specification #219
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #219 +/- ##
==========================================
- Coverage 95.46% 95.36% -0.11%
==========================================
Files 79 80 +1
Lines 2074 2069 -5
Branches 258 266 +8
==========================================
- Hits 1980 1973 -7
+ Misses 93 90 -3
- Partials 1 6 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
I'm open to this and think it probably is good to make the query context explicit.
How independent are VCs and QCs? Should VCs no longer have a getQueryContextForDatabaseAdaptorFlavor()
method if application code that works with VCs will always have a QC anyway since VCs and QCs are now passed around together?
What are the potential consequences if a VC is passed in with a QC, but vc.getQueryContextForDatabaseAdaptorFlavor() !== qc
?
Should we pair together VCs and QCs in an object like: interface EntityContext { viewerContext; queryContext; }
? (I'm thinking probably no for now. Keep the values flatter.)
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.
I'd be very happy with something like this in www as I'm always super paranoid of forgetting to pass a qc.
They are related in that a ViewerContext is the entry point into the entity framework from an application (it has the reference to the EntityCompanionProvider which is the "instance" of the entity framework). So for an application to get a vended QueryContext, it must go through the viewer context by definition. But they are not tied together and are independent. There can be many flavors of viewer context (depending on the application) and both transactional and non-transactional query contexts being used for any loader/mutator call at any point.
I think maybe we should rename So, to answer your question, all non-transactional query context (
I'd say no for now, but if/when we have more database adaptor flavors we may need to reassess. But even then, one could imagine just having single instance of a viewer context being passed around and then multiple query contexts being used for multiple databases. This is all theoretical though. |
a24411f
to
7e40a52
Compare
This reverts commit 8b0b31f.
Reverted due to the integration of this into our first-party codebase (www) being too unwieldy (6k tsc errors). Going to come up with a different approach, maybe something more codemod-able. |
Why
This is a RFC.
The proposal is to require the
queryContext
argument to reduce the likelihood of accidental omittance within a transaction block in application code.At Expo, we've noticed sometimes a transaction will be started and the loader/mutator calls within it may accidentally not include the query context (which must be explicitly supplied as an arg to run within the transaction):
Closes ENG-11824.
How
The proposed change is to always require
queryContext
. At Expo, we added a method to ourViewerContext
subclass to vend the defaultEntityQueryContext
(non-transactional) for our default database adaptor flavor. I added a similar method toTestViewerContext
within this repo to demonstrate the convenience accessor.RFC
Test Plan
yarn tsc