-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Data Layer: Fix POST-ing formData
with an apiVersion
while introducing apiNamespace
#13028
Conversation
formData
with an apiVersion
while introducing apiNamespace
: successes.forEach( handler => dispatch( extendAction( handler, successMeta( nextData ) ) ) ); | ||
}; | ||
|
||
const request = fetcherMap( method, wpcom.req )( action, requestCallback ); |
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.
yaaaaaay
query, | ||
callback | ||
), | ||
POST: ( { body = {}, formData, path, query = {}, }, callback ) => wpcomReq.post( |
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.
love it. makes all this much more explicit.
|
||
it( 'should send with query', () => { | ||
getFooAction.query = { | ||
apiVersion: 'v2.0', |
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 think apiVersion doesn't have a leading v
. should be 2.0
i think?
|
||
it( 'should send formData with query', () => { | ||
postFooAction.formData = [ [ 'foo', 'bar' ], ]; | ||
postFooAction.query = { apiVersion: 'v1.1' }; |
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.
ditto, i think it's just 1.1
, not v1.1
.
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.
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.
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.
Yep, I think I got confused with the default value used for apiVersion
in the http
action creator: https://github.com/Automattic/wp-calypso/blob/master/client/state/data-layer/wpcom-http/actions.js#L23
Now I wonder if there is a special case for v1
or if we should also remove the v
in there? In #13022 @dmsnell got rid of the default but we're still using v1
in the tests, might be worth tackling it there as well.
query: Object.assign( | ||
{ apiVersion }, | ||
query, | ||
apiNamespace && { apiNamespace }, |
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.
note that this will break requests which provide an apiNamespace
as they will fail if both values are present 😄
|
||
describe( '#fetcherMap', () => { | ||
const wpcomReq = {}; | ||
const noopCallback = () => {}; |
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.
seems awkward to name this noopCallback
instead of just noop
.
note also that lodash.noop
also exists
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.
TIL, will use lodash.noop
:)
getFooAction.query = { | ||
apiVersion: '2.0', | ||
apiNamespace: 'wp/v2', | ||
}; |
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.
this kind of mutation irks me because it hides the things that aren't here. interested at all in rewriting immutably?
const action = { ...baseAction, query: { param: 'test' } };
// or since it's not too big we could envision just writing it out each time
const wpcom = {
get: spy(),
post: spy(),
};
beforeEach( () => wpcom.get.reset() );
const action = {
method: 'GET',
path: '/foo',
query: { apiVersion: '1.3' }
}
we actually wrote fewer lines this way overall…
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 honestly don't feel strongly about either :) I went that way (let
+ new spy
-s in beforeEach
to match what was already there for dispatch
/ next
). If we go with const
+ resets
, it's probably worth updating the entire file.
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.
sounds fair either way. you can blame me for any inconsistencies 😄
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.
Thanks for this work @bperson - I kind of like the general changes you made. Please note that this is unmergable due to the current bug in the way it assigns apiVersion
and apiNamespace
but I think you were ware of that.
Something about the fetcher map stands out to me. It's not something I can quite pin down, but I am going to stew on it a bit. Please nag me if I delay too much (will be AFK for the next few days)
any reason to chose wpcomReq
instead of just req
?
Yep for the unmerge-ability, I will revert 33c7293 and it's probably worth waiting for #13022 to land and rebasing on top of it.
It's definitely becoming a weird beast: a kind of meta-mapper of args :D . On top of that the
I feel like |
just curious. |
I find this pretty confusing as well. |
@dmsnell np, I'm watching your PR and will rebase / push force this branch (warning if someone's actively using this branch :) ). I don't expect that much change with the current status (since I've reverted my commit for the addition of |
@nylen do you find confusing the usage of |
@bperson This PR needs a rebase |
…n the `query` wpcom's `req.post` has the signature: `params, [query], body, [callback]` which means positionnal arguments will move around based on the function's arity: 4: `params, query, body, callback` 3: `params, query, body` or `params, body, callback` 2: `params, body` With that in mind, the use of `compact` in the data-layer considerably complexifies the situation, as we can hit those various arities for many combinations of arguments. This tries to simplify the process while fixing a few edge cases already encountered in a few past PRs (#12135, #12839): If you want to pass `formData` (in `params`) with an `apiVersion` (in `query`), you NEED to pass a `body`, but any truth-y body will overwrite the `formData` in the HTTP request. This disqualifies the usage of `compact` as you - sometimes - want to pass a false-y values. (PR #12135) If you want to just pass an `apiVersion` (in `query`), you need - at least - another argument to have an arity of 3, which means you need to pass an empty body (PR #12839)
75bcd31
to
4bb79f6
Compare
Yes, but it's probably too late to change that now.
I think When I see a variable named |
@nylen just a side note, but that's not usually the case, not with |
Right, this is exactly what I am taking issue with. It would be better if we had called that |
I think that's what we're finding confusing :) Outside of As another sidenote, I thought about bypassing the entire [0] https://github.com/Automattic/wpcom.js/blob/master/lib/util/request.js |
@bperson do we have a status update on this? is there work to be done? are you waiting on us? |
I still think there is a need to make it more explicit how the various arities of the wpcom interface are handled. I've just re-read #14651 which seems to have become the hub for this issue?. For now though, this isn't a blocker to close my trial and it's probably safe to say that someone with more experience in calypso could lead that effort way better than me (trial-er for life 🤘 ) so maybe this should be closed and the ideas re-used in a stronger effort in July as mentioned on #14651? |
Ok so this started as part of my trial where I need to use the
wp/v2
namespace: #12733.I initially figured it was just a matter of adding
apiNamespace
in thehttp
action creator and quickly ended up in the deep hole of understanding why we weren't passingquery
forPOST
: https://github.com/Automattic/wp-calypso/blob/master/client/state/data-layer/wpcom-http/actions.js#L38I just saw @dmsnell approach in #13022 which probably is better as we're passing only one of
apiNamespace
/apiVersion
, but I still feel like there is value in 976dec9 and f4e4115, 33c7293 is included as context for why I ended up here :) I am pretty sure #12839 breaks what #12135 tried to do.