Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit ab4693b

Browse files
authored
Merge pull request #7775 from magento/kh-reviews
GraphQL: Add coverage for product reviews
2 parents e8a8bc7 + 0af0453 commit ab4693b

File tree

8 files changed

+357
-2
lines changed

8 files changed

+357
-2
lines changed

src/_data/toc/graphql.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ pages:
111111
- label: isEmailAvailable query
112112
url: /graphql/queries/is-email-available.html
113113

114+
- label: productReviewRatingsMetadata query
115+
url: /graphql/queries/product-review-ratings-metadata.html
116+
exclude_versions: ["2.3"]
117+
114118
- label: products query
115119
url: /graphql/queries/products.html
116120

@@ -192,6 +196,10 @@ pages:
192196
- label: createPayPalExpressToken mutation
193197
url: /graphql/mutations/create-paypal-express-token.html
194198

199+
- label: createProductReview mutation
200+
url: /graphql/mutations/create-product-review.html
201+
exclude_versions: ["2.3"]
202+
195203
- label: deleteCustomerAddress mutation
196204
url: /graphql/mutations/delete-customer-address.html
197205

src/_includes/graphql/customer-output-24.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Attribute | Data Type | Description
2626
`middlename` |String | The customer's middle name
2727
`orders(<FilterCriteria>)` | {{ customeroutput_text }} | A list of the customer's placed orders{{ crossref_text }}
2828
`prefix` | String | An honorific, such as Dr., Mr., or Mrs.
29+
`reviews(pageSize: Int = 20 currentPage: Int = 1)` | ProductReviews! | The list of reviews of the product
2930
`reward_points` | RewardPoints | Details about the customer's reward points
3031
`suffix` | String | A value such as Sr., Jr., or III
3132
`taxvat` | String | The customer's Tax/VAT number (for corporate customers)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The `ProductReview` object contains details about a product review. It contains the following attributes.
2+
3+
Attribute | Data Type | Description
4+
--- | --- | ---
5+
`average_rating` | Float! | The average rating for product review
6+
`created_at` | String! | Date indicating when the review was created
7+
`nickname` | String! | The customer's nickname. Defaults to the customer name, if logged in
8+
`product` | ProductInterface! | Contains details about the reviewed product
9+
`ratings_breakdown` | [ProductReviewRating!]! | An array of ratings by rating category, such as quality, price, and value
10+
`summary` | String! | The summary (title) of the review
11+
`text` | String! | The review text
12+
13+
### ProductReviewRating attributes {#ProductReviewRating}
14+
15+
The `ProductReviewRating` object contains the following attributes.
16+
17+
Attribute | Data Type | Description
18+
--- | --- | ---
19+
`name` | String! | The label assigned to an aspect of a product that is being rated, such as quality or price
20+
`value` | String! | The rating value given by customer. By default, possible values range from 1 to 5
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
group: graphql
3+
title: createProductReview mutation
4+
---
5+
6+
The `createProductReview` mutation adds a review for the specified product. Use the [`productReviewRatingsMetadata` query]({{page.baseurl}}/graphql/queries/product-review-ratings-metadata.html) to return a list of rating categories and possible values.
7+
8+
## Syntax
9+
10+
`createProductReview(input: CreateProductReviewInput!): CreateProductReviewOutput!`
11+
12+
## Example usage
13+
14+
In the following example, Roni gives product `WH08` four stars overall, three stars for value, and four stars for quality.
15+
16+
**Request:**
17+
18+
```graphql
19+
mutation {
20+
createProductReview(
21+
input: {
22+
sku: "WH08",
23+
nickname: "Roni",
24+
summary: "Great looking sweatshirt",
25+
text: "This sweatshirt looks and feels great. The zipper sometimes sticks a bit.",
26+
ratings: [
27+
{
28+
id: "NA==",
29+
value_id: "MTk="
30+
}, {
31+
id: "MQ==",
32+
value_id: "NA=="
33+
}, {
34+
id: "Mg==",
35+
value_id: "OA=="
36+
}
37+
]
38+
}
39+
) {
40+
review {
41+
nickname
42+
summary
43+
text
44+
average_rating
45+
ratings_breakdown {
46+
name
47+
value
48+
}
49+
}
50+
}
51+
}
52+
```
53+
54+
**Response:**
55+
56+
```json
57+
{
58+
"data": {
59+
"createProductReview": {
60+
"review": {
61+
"nickname": "Roni",
62+
"summary": "Great looking sweatshirt",
63+
"text": "This sweatshirt looks and feels great. The zipper sometimes sticks a bit.",
64+
"average_rating": 73.33,
65+
"ratings_breakdown": [
66+
{
67+
"name": "Quality",
68+
"value": "4"
69+
},
70+
{
71+
"name": "Value",
72+
"value": "3"
73+
},
74+
{
75+
"name": "Overall",
76+
"value": "4"
77+
}
78+
]
79+
}
80+
}
81+
}
82+
}
83+
```
84+
85+
## Input attributes
86+
87+
The `CreateProductReviewInput` input object defines the product review.
88+
89+
### CreateProductReviewInput attributes {#CreateProductReviewInput}
90+
91+
The `CreateProductReviewInput` object contains the following attributes:
92+
93+
Attribute | Data Type | Description
94+
--- | --- | ---
95+
`nickname` | String! | The customer's nickname. Defaults to the customer name, if logged in
96+
`ratings` | [ProductReviewRatingInput!]! | Ratings details by category. e.g price: 5, quality: 4 etc
97+
`sku` | String! | The SKU of the reviewed product
98+
`summary` | String! | The summary (title) of the review
99+
`text` | String! | The review text.
100+
101+
### ProductReviewRatingInput attributes {#ProductReviewRatingInput}
102+
103+
The `ProductReviewRatingInput` object contains the following attributes:
104+
105+
Attribute | Data Type | Description
106+
--- | --- | ---
107+
`id` | String! | An encoded rating ID
108+
`value_id` | String! | An encoded rating value ID
109+
110+
## Output attributes
111+
112+
The `CreateProductReviewOutput` output object contains the following attribute:
113+
114+
Attribute | Data Type | Description
115+
--- | --- | ---
116+
`review` | ProductReview! | Contains the completed product review
117+
118+
### ProductReview attributes {#ProductReview}
119+
120+
{% include graphql/product-review.md %}

src/guides/v2.4/graphql/product/product-interface.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ Attribute | Data type | Description
4646
`price_range` | [PriceRange!](#PriceRange) | A `PriceRange` object, indicating the range of prices for the product
4747
`price_tiers` | [TierPrice] | An array of `TierPrice` objects
4848
`product_links` | [ProductLinksInterface] | An array of [ProductLinks](#ProductLinks) objects
49+
`rating_summary` | Float! | The average of all the ratings given to the product
4950
`related_products` | [ProductInterface] | An array of related products
51+
`review_count` | Int! | The total count of all the reviews given to the product
52+
`reviews(pageSize: Int = 20 currentPage: Int = 1)` | [ProductReviews!](#ProductReviews) | The list of reviews of the product
5053
`short_description` | ComplexTextValue | An object that contains a short description of the product. Its use depends on the store's theme. The object can include simple HTML tags
5154
`sku` | String | A number or code assigned to a product to identify the product, options, price, and manufacturer
5255
`small_image` | [ProductImage](#ProductImage) | An object that contains the URL and label for the small image used on catalog pages
@@ -153,6 +156,19 @@ Attribute | Data Type | Description
153156
`code` | PriceAdjustmentCodesEnum | One of `tax`, `weee`, or `weee_tax`.
154157
`description` | PriceAdjustmentDescriptionEnum | Indicates whether the entity described by the code attribute is included or excluded from the adjustment.
155158

159+
#### ProductReviews object {#ProductReviews}
160+
161+
`ProductReviews` contains an array of reviews written about the product.
162+
163+
Attribute | Data Type | Description
164+
--- | --- | ---
165+
`items` | [ProductReview]! | An array of product reviews
166+
`page_info` | [SearchResultPageInfo!]({{page.baseurl}}/graphql/queries/products.html#SearchResultPageInfo) | Metadata for pagination rendering
167+
168+
#### ProductReview object {#ProductReview}
169+
170+
{% include graphql/product-review.md %}
171+
156172
#### ProductLinks object {#ProductLinks}
157173

158174
`ProductLinks` contains information about linked products, including the link type and product type of each item.

src/guides/v2.4/graphql/queries/customer.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,39 @@ Attribute | Data Type | Description
501501

502502
{% include graphql/customer-orders-output.md %}
503503

504+
#### ProductReviews object {#ProductReviews}
505+
506+
`ProductReviews` contains an array of reviews written about the product.
507+
508+
Attribute | Data Type | Description
509+
--- | --- | ---
510+
`items` | [ProductReview]! | An array of product reviews
511+
`page_info` | [SearchResultPageInfo!]({{page.baseurl}}/graphql/queries/products.html#SearchResultPageInfo) | Metadata for pagination rendering
512+
513+
#### ProductReview object {#ProductReview}
514+
515+
{% include graphql/product-review.md %}
516+
517+
### Wishlist attributes {#Wishlist}
518+
519+
Attribute | Data type | Description
520+
--- | --- | ---
521+
`items` | [[WishlistItem](#wishlistitem)] | An array of items in the customer's wish list
522+
`items_count` | Int | The number of items in the wish list
523+
`id` | ID | The unique identifier of the wish list
524+
`sharing_code` | String | An encrypted code that Magento uses to link to the wish list
525+
`updated_at` | String | The time of the last modification to the wish list
526+
527+
#### WishlistItem attributes {#wishlistitem}
528+
529+
Attribute | Data type | Description
530+
--- | --- | ---
531+
`added_at` | String | The time when the customer added the item to the wish list
532+
`description` | String | The customer's comment about this item
533+
`id` | Int | The wish list item ID
534+
`product` | [ProductInterface]({{ page.baseurl }}/graphql/product/product-interface.html) | The ProductInterface contains attributes that are common to all types of products. Note that descriptions may not be available for custom and EAV attributes
535+
`qty` | Float | The quantity of this wish list item
536+
504537
### Store credit attributes
505538

506539
In {{site.data.var.ee}}, the merchant can assign store credit to customers. Magento maintains the history of all changes to the balance of store credit available to the customer. The customer must be logged in to access the store credit history and balance.
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
group: graphql
3+
title: productReviewRatingsMetadata query
4+
---
5+
6+
The `productReviewRatingsMetadata` query returns the active ratings attributes and the values each rating can have. In Luma, these values are one star through five stars.
7+
8+
Use the [`createProductReview` mutation]({{page.baseurl}}/graphql/mutations/create-product-review.html) to add a product review.
9+
10+
## Syntax
11+
12+
`productReviewRatingsMetadata: ProductReviewRatingsMetadata!`
13+
14+
## Example usage
15+
16+
The following query returns the metadata for all active ratings attributes. In this example, the default `Rating` attribute has been renamed to `Overall`, and the `Quality` and `Value` attributes have been enabled.
17+
18+
**Request:**
19+
20+
```graphql
21+
query {
22+
productReviewRatingsMetadata {
23+
items {
24+
id
25+
name
26+
values {
27+
value_id
28+
value
29+
}
30+
}
31+
}
32+
}
33+
```
34+
35+
**Response:**
36+
37+
```json
38+
{
39+
"data": {
40+
"productReviewRatingsMetadata": {
41+
"items": [
42+
{
43+
"id": "NA==",
44+
"name": "Overall",
45+
"values": [
46+
{
47+
"value_id": "MTY=",
48+
"value": "1"
49+
},
50+
{
51+
"value_id": "MTc=",
52+
"value": "2"
53+
},
54+
{
55+
"value_id": "MTg=",
56+
"value": "3"
57+
},
58+
{
59+
"value_id": "MTk=",
60+
"value": "4"
61+
},
62+
{
63+
"value_id": "MjA=",
64+
"value": "5"
65+
}
66+
]
67+
},
68+
{
69+
"id": "MQ==",
70+
"name": "Quality",
71+
"values": [
72+
{
73+
"value_id": "MQ==",
74+
"value": "1"
75+
},
76+
{
77+
"value_id": "Mg==",
78+
"value": "2"
79+
},
80+
{
81+
"value_id": "Mw==",
82+
"value": "3"
83+
},
84+
{
85+
"value_id": "NA==",
86+
"value": "4"
87+
},
88+
{
89+
"value_id": "NQ==",
90+
"value": "5"
91+
}
92+
]
93+
},
94+
{
95+
"id": "Mg==",
96+
"name": "Value",
97+
"values": [
98+
{
99+
"value_id": "Ng==",
100+
"value": "1"
101+
},
102+
{
103+
"value_id": "Nw==",
104+
"value": "2"
105+
},
106+
{
107+
"value_id": "OA==",
108+
"value": "3"
109+
},
110+
{
111+
"value_id": "OQ==",
112+
"value": "4"
113+
},
114+
{
115+
"value_id": "MTA=",
116+
"value": "5"
117+
}
118+
]
119+
}
120+
]
121+
}
122+
}
123+
}
124+
```
125+
126+
## Input attributes
127+
128+
Not applicable
129+
130+
## Output attributes {#Categories}
131+
132+
The `ProductReviewRatingsMetadata` output object contains the `items` object.
133+
134+
Attribute | Data type | Description
135+
--- | --- | ---
136+
`items` | [ProductReviewRatingMetadata!]! | A list of product reviews, sorted by position
137+
138+
### ProductReviewRatingMetadata attributes {#ProductReviewRatingMetadata}
139+
140+
The `ProductReviewRatingMetadata` object contains the following attributes.
141+
142+
Attribute | Data type | Description
143+
--- | --- | ---
144+
`id` | String! | | An encoded rating ID
145+
`name` | String! | The label assigned to an aspect of a product that is being rated, such as quality or price
146+
`values` | [ProductReviewRatingValueMetadata!]! | A list of product review ratings, sorted by position
147+
148+
### ProductReviewRatingValueMetadata attributes {#ProductReviewRatingValueMetadata}
149+
150+
The `ProductReviewRatingValueMetadata` object contains the following attributes.
151+
152+
Attribute | Data type | Description
153+
--- | --- | ---
154+
value | String! | A ratings scale, such as the number of stars awarded
155+
value_id | String! | An encoded rating value ID

0 commit comments

Comments
 (0)