-
Notifications
You must be signed in to change notification settings - Fork 221
Migrate REST API usage to the Store API #2282
Conversation
Conflict on initial commit 😆 |
@senadir Not marked for review yet, fixing tests. |
1d6d251
to
be3eadd
Compare
@senadir I'm going to do some more testing tomorrow and I had to comment out the tests for with-attributes - I redid the HOC with hooks and it isn't compatible with existing tests. Marking for review though. |
Size Change: -12.7 kB (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
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.
Okay, this was a huge refactor, wonderful job Mike!
I spotted a small regression that I think is easy to fix, once it's fixed feel free to merge.
@@ -24,23 +20,21 @@ const getProductsRequests = ( { | |||
queryArgs = [], | |||
} ) => { | |||
const defaultArgs = { | |||
per_page: IS_LARGE_CATALOG ? 100 : -1, | |||
per_page: IS_LARGE_CATALOG ? 100 : 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.
Wouldn’t 0 return no product?
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.
Nope. I noticed some functions treat 0 as "unlimited" and adopted that instead of -1 which also makes validation easier.
/** | ||
* ProductCategories class. | ||
*/ | ||
class ProductCategories extends AbstractTermsRoute { |
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.
@@ -31,17 +31,36 @@ public function prepare_objects_query( $request ) { | |||
'paged' => $request['page'], | |||
'post__in' => $request['include'], | |||
'post__not_in' => $request['exclude'], | |||
'posts_per_page' => $request['per_page'], | |||
'posts_per_page' => $request['per_page'] ? $request['per_page'] : -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.
I know that if per_page
is set to 0, this will evaluate to -1, but why does that? wouldn't make sense to let the client use the same logic as WP?
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.
it's easier to check ! per_page then set to -1 than handle 0 and -1 separately. The schema validates from 0 and has a message than leaving blank, or using 0, maps to unlimited.
Some functions in WP use 0 instead of -1 - I think the terms query object.
Good catch @senadir I am using the count from WP, but some counts enhance to include children terms. Will revise. |
Upon reviewing the REST API overrides in blocks, to see what needed to be ported to the REST API itself, I found that most endpoints simply needed to expand access capabilities to authors/non-admin users.
As well as expanding access rights, some of the endpoints were then needing to shape data to hide private things, or return data in a specific opinionated format. This didn't seem like a good solution to me, so I worked through each endpoint to see if the Store API could be used instead. Store API is public, so there should be no auth issues in doing this.
I had success with the existing Store endpoints (products, attributes) so decided to port over some of the other endpoints too, creating new Store API endpoints for tags, categories, reviews all following similar practices and only allowing READ access to public data.
This PR contains that work :)
How to test the changes in this Pull Request: