-
-
Notifications
You must be signed in to change notification settings - Fork 131
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: collectionStats
query added
#785
feat: collectionStats
query added
#785
Conversation
collectionStats
query added
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.
Thist is great! I think you are on the correct track but I would advise the following.
Instead of having the field on the Root type, it needs to be inside the Products (and Product?) field.
The collection stats depend on the query made on the product as the count of attributes changes according to it.
Important
In addition to the above attributes, all product list attributes are supported. This allows you to get data for a certain subset of products. See the products API list products section for the full list.
GET /products/collection-data?calculate_attribute_counts[0][query_type]=or&calculate_attribute_counts[0][taxonomy]=pa_sizes&attributes[0]&[attribute]=pa_color&attributes[0][slug]=red
would be similar to do
query GetProducts {
products(where: {taxonomyFilter: {filters: {taxonomy: PACOLOR, terms: "red"}}}) {
collectionStats(taxonomies: [{taxonomy: PASIZES, relation: OR}]) {
attributeCounts {
termId
count
}
}
nodes {
title
}
}
}
The results here should be the term count of the attribute SIZES
for all products that have a COLOR
attribute of red
'page' => [ | ||
'type' => 'Int', | ||
'description' => __( 'Page of results to return.', 'wp-graphql-woocommerce' ), | ||
], | ||
'perPage' => [ | ||
'type' => 'Int', | ||
'description' => __( 'Number of results to return per page.', 'wp-graphql-woocommerce' ), |
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 we should return all the results. I don't see any type of pagination in the Store API implementation.
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.
Because this result list can get pretty monstrous and it would be pretty foolishly to not do this. And REST is already caching the full result list so might as well take advantage of that. If you want the full list don't set any arguments, these arguments are if you actually want pagination but doesn't force it on the client
'stock_status_counts' => null, | ||
'rating_counts' => null, | ||
]; | ||
$filters = new ProductQueryFilters(); |
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 would consider recreating this class inside WooGraphQL plugin so we can modify it accordingly and not be subject to non-existent query params that only make sense in the REST API context.
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.
Naw, having gone down that route with the checkout
mutation. I can say with confidence this is more future-proof and easier to maintain/refactor in the likely event of a breaking change.
870f945
to
c556ab7
Compare
return $request; | ||
} | ||
|
||
$key_mapping = [ |
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.
Do you think we would need a filter here for extensibility?
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.
Not at this time, because the functionality of ProductQueryFilters is kinda limited at the moment and not extendable by hooks or extra params, we can revisit this once it has been expanded upon or made extendable is some way 🤔.
Your checklist for this pull request
Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.
🚨Please review the guidelines for contributing to this repository.
What does this implement/fix? Explain your changes.
Adds
collectionStats
query. Here's an example usage.Note: the query is currently in flux and without hooks for modification because it utilizes the functionality of the woocommerce-blocks Store API's ProductCollection endpoint which is still kinda limited. It works for the most part, but the attributeCounts field only takes the where.attributes field is taken into account with calculating the attribute counts. Meaning it's not possible to filter the result by any "non product attribute" taxonomies at the time of this release.
Example
TODO
collectionStats
query.Does this close any currently open issues?
…
Any relevant logs, error output, GraphiQL screenshots, etc?
(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)
Any other comments?
…
Where has this been tested?