-
Notifications
You must be signed in to change notification settings - Fork 8
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
new version of http
that uses fetch
#283
Comments
There are a few things going on at the same time here
Each is a big and breaking update, but it might make sense to consider all of them together. |
This is the expandReferences dilemma: expandReferencesexpand references find what I call a "deferred value" - a value nested inside a function which must be resolved against the latest state.
So this pattern, with two nested deferred values, should be totally fine:
This pattern defers the whole query object, which is also fine (and for my money, better)
I do not know why this recursion is needed. Nesting deferred values doesn't do anything but complicate the code - you don't get a different value for state or anything. I actually think it's an antipattern. Basically every adaptor supports/depends on this recursive expansion. If we change it, we break every single adaptor in a really subtle way. expandRequestReferencesThe common.http functions expose all the parameters of an axios request to the Many of axios's options look like deferred values to our recursive expander, so we'll try and invoke them. And almost certainly break something. So It looks inelegant from the outside, but it's a good and necessary solution. |
Replacing axiosRemove the dependency on Axios and unidici do not share an API. And unfortunately common exposes axios's options directly to consumers. Also remember that common exposes the axios object directly. Jobs which depend on this will be incompatible with this version, and authors writing new jobs against the new adaptor may need to retrain themselves. We had been looking at using
Options:
Whatever we do, we should continue to expand the |
Breaking ChangesWhat do I mean when I say something will break? That's not always obvious for us Existing jobs on platform will continue to run because they're version locked to an adaptor. And old adaptors will not be affected by anything we do (if we change common, and an old adaptor depends on common, it'll install within the major version). When we migrate platform jobs into Lightning, they should continue to run so long as we continue to lock versions. That's an important note for the migration strategy - we should NOT migrate and upgrade. So the only people affected by breakges are people writing new jobs, which I think is mostly our internal team. There are two things I'm concerned about:
If we're going to break something, it really ought to have meaningful impact and benefit. It's often a good idea to add a totally clean new API, rather than tweaking or adjusting an old one. Benefits of this are:
|
Removing common.httpDo we even want to keep common.http? We've started developing a pattern where each adaptor provides its own http helper functions using This is based on the idea that adaptors can just use the native request handler, a simple and convenient low-level API that we can't improve. This gets a bit less clean if we switch to Watching this approach get rolled out across a few adaptors, I can also see that it's generating a lot of boilerplate code. It's becoming a barrier to template creation - the first thing you have to do is write a bunch of low level http handlers. I think we're actually making life harder. A final note on this is that this pattern discourages uniformity, which may be bad for job authors. If adaptor A and adaptor B take very different approaches to http handling, the display (or not) of http errors in the log may very in quality, location and content. Isn't it better for us to abstract a bunch of this out, to use our expertise to write a really tight pattern for http, and just give template authors clean hooks to use it? Better devx for adaptor authors and job writers. I think yes, we should remove common.http, but we should replace it with a bunch of non-operation, non-expanding helper functions which wrap |
ProposalOk, having been through a bunch of this, here's a proposal for what to do about http. This is a huge project, a lot of work, with some design needed: Guiding principles
Add http helpers to common/util #314We write a new layer of http functions in common/util, designed to be used in other adaptors. The new functions are not operations or operation factories. They do not take and return state. They do not expand references. We present get/put/post etc functions which wrap Options allows you to pass query arguments and headers and stuff. It will also allow you to map error bespoke messages to error codes via simple mapping, ie I'd also like to design a url builder function to make URL construction easier. The full signatures here are to be decided. The handlers might be stateful - perhaps optionally. This would allow an adaptor to set auth and agent and maybe error messages at the start of execute, and reduce repetition thereafter. Remove common.http #315common.http is for the axe. The whole thing should go. It will be replaced by the new helpers in common.util. We could deprecate it for one major version. This would allow us to phase the work more effectively and be a little bit more gentle on job authors. Rewrite language-http #316Probably the biggest change is I would also like to update http to use the new format of expand references, without any of the skip stuff. I don;t think we need a confusing I basically want a license to remove the Update the templateAdaptors should use get handlers in common/util, not use unidici directly. I think this removes the need to create custom handlers for each adaptor in a Util file, simplifying the code. The template should be updated (again) to reflect this. We should go over each existing adaptor which uses the pattern and make sure it's up to date. expandReferencesI don't want to touch it. I think this will just introduce subtle bugs for no good reason. We should continue to support the old, recursive function. The language-http rewrite should simplify the Note that, while we're introducing a major change, we should update every adaptor to use the new expandReferences function, and deprecate or remove the old one (there are issues for this). Maybe we should check that the documentation recommends you don't rely on recursion- or indeed doesn't tell you you CAN recurse. Pushing away from that pattern now may enable us to change it later, if there's a compelling reason to do so. Other adaptors #317We should go through each adaptor, remove axios and common.http re-exports, update expandReferences, remove otherhttp libraries (ie superagent) and bump the major version. |
Closing in favour of epic #320 and the sundry issues under it |
build a new fetch-based version:
expandReferences
dilemmacommon.http
since all users will now have access tofetch
directlyThe text was updated successfully, but these errors were encountered: