It would be great to get reviews for products back with a simple products request. Reviews are technically comments on products post types.
The query I'm hoping to write to get these back would be something like the following:
{
wpgraphql {
products {
edges {
node {
reviewCount
reviews {
content
rating
author
date
id
approved
}
}
}
}
}
}
At the moment, 'reviewCount` is already enabled.
Thanks!
is the reviewCount supposed to be the total number of reviews? If so, that should be presented on the edge and not on the node, as it's not a property of the node, but a property of the relationship between the product and the review.
So, something like:
{
wpgraphql {
products {
edges {
node {
reviews {
totalCount
nodes {
content
rating
author
date
id
approved
}
}
}
}
}
}
}
This will allow you to do things like filter the connection, for example (made up example):
{
wpgraphql {
products {
edges {
node {
reviews(where: { userFrom: "colorado" }) {
totalCount
nodes {
content
rating
author
date
id
approved
}
}
}
}
}
}
}
We could filter the reviews by users in Colorado, and the reviews.totalCount should reflect the number of reviews on that product, for that filter.
Just some thoughts on Schema design 馃槃
@jasonbahl It can and probably will be expose it on the edge, but it's stored on the product. This behavior is built into WooCommerce.
shouldn't matter where it's stored. For a caching client, like Apollo, etc you want edge data cached on the edge. Specifically when you get into things like filtering, as in the example above. That count would be dynamic and not a property of the product.
I agree with you design idea, I'm adding reviewRating to the edge as well.
Most helpful comment
is the
reviewCountsupposed to be the total number of reviews? If so, that should be presented on theedgeand not on thenode, as it's not a property of thenode, but a property of the relationship between the product and the review.So, something like:
This will allow you to do things like filter the connection, for example (made up example):
We could filter the reviews by users in Colorado, and the
reviews.totalCountshould reflect the number of reviews on that product, for that filter.Just some thoughts on Schema design 馃槃