Create mechanism to add experimental features to Apollo Client#12915
Create mechanism to add experimental features to Apollo Client#12915phryneas merged 3 commits intorelease-4.1from
Conversation
🦋 Changeset detectedLatest commit: 49c0097 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: 7f75dba09c2b39a5bca5f17f |
commit: |
size-limit report 📦
|
3bdce02 to
5a67855
Compare
e78107d to
3fe4502
Compare
jerelmiller
left a comment
There was a problem hiding this comment.
Comment looks good. Up to you whether you like the suggestion or want to keep it as-is.
| * Allows passing in "experiments", experimental features that might one day | ||
| * become part of Apollo Client's core functionality. | ||
| * Keep in mind that these features might change the core of Apollo Client. | ||
| * Do not pass in experiments that are not provided by Apollo. |
There was a problem hiding this comment.
| * Do not pass in experiments that are not provided by Apollo. | |
| * Proceed with caution when supplying experiments that are not provided by Apollo. |
Could we perhaps be a bit gentler here and instead of fully discouraging custom experiments, just say that they carry some risk? I don't want to entirely discourage someone from trying something in their own environment that could potentially be contributed back to the client, but agree we need to say that it carries risk. Thoughts?
There was a problem hiding this comment.
I don't feel good with that idea - by themselves, experiments don't allow you to do anything you couldn't already do in userland without them. They just encapsulate and hide that dangerous stuff happens.
So if someone were to create something like this in userland, I think I'd prefer if they would do
const client = new ApolloClient()
client['queryManager'].prototype.newMethod = () => { /* ... */ }which makes it very visible that this is a very flimsy and potentially dangerous thing to do.
I don't really want experiments to live outside of our control, since when we change any of our internals (e.g. adding newMethod on our side), it might break experimentes, or get broken by an experiment. We can only guarantee that that doesn't happen if we are the only people writing and distributing them.
There was a problem hiding this comment.
We talked this through on video :)
This will allow to execute code in the constructor of Apollo Client, essentially allowing for us to modify anything, from overwriting methods, swapping out prototypes, overwriting hook behaviour etc.
These could be exposed as exports from
@apollo/client/experiments/name, with usage like